CodeForces 1574C Slay the Dragon

阅读: 评论:0

CodeForces 1574C Slay the Dragon

CodeForces 1574C Slay the Dragon

题意:

现有 n 个英雄与一个龙,每个英雄有一个能力值,龙有一个攻击值 xx与一个防御值 y。现在你要派一个人去打龙,但是这个人的能力值必须大于等于龙的防御值;剩下的人守护城堡,他们的力量值和大于等于龙的攻击。一个金币可以提升一个人一点能力值,问最少需要多少金币。

题解:

两种情况,找刚好打的过龙的人去,或者就是找差一点打的过的去,判断一下哪个更优就好;(这题卡输入。。。)

代码:

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;ll shu[200005];
int main() 
{ll n;scanf("%lld", &n);ll sum = 0;for (int i = 0; i < n; i++){ll e;scanf("%lld", shu+i);sum += shu[i];}sort(shu, shu + n);ll t;scanf("%lld", &t);while (t--){ll x, y, as1 = LLONG_MAX, as2 = LLONG_MAX;scanf("%lld%lld", &x, &y);ll a2 = lower_bound(shu, shu + n, x) - shu;ll a1;if (a2 != n){a1 = shu[a2];if (sum - a1 >= y)as1 = 0;else{ll cnt = (y - (sum - a1));as1 = cnt;}}if (a2 != 0){a2--;a1 = shu[a2];ll num = x - a1;if (sum + num - x >= y){as2 = num;}else{ll cnt = (y - (sum + num - x));as2 = num + cnt;}}//cout << as1 << " " << as2 << endl;cout << min(as1, as2) << endl;}
}

本文发布于:2024-01-27 20:37:55,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17063590772498.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:CodeForces   Dragon   Slay
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23