ACM----Codeforces Round #700 (Div. 2)B. The Great Hero
The great hero guards the country where Homer lives. The hero has attack power AA and initial health value BB. There are nn monsters in front of the hero. The ii-th monster has attack power aiai and initial health value bibi.
The hero or a monster is said to be living, if his or its health value is positive (greater than or equal to 11); and he or it is said to be dead, if his or its health value is non-positive (less than or equal to 00).
In order to protect people in the country, the hero will fight with monsters until either the hero is dead or all the monsters are dead.
- In each fight, the hero can select an arbitrary living monster and fight with it. Suppose the ii-th monster is selected, and the health values of the hero and the ii-th monster are xx and yy before the fight, respectively. After the fight, the health values of the hero and the ii-th monster become x−aix−ai and y−Ay−A, respectively.
Note that the hero can fight the same monster more than once.
For the safety of the people in the country, please tell them whether the great hero can kill all the monsters (even if the great hero himself is dead after killing the last monster).
Each test contains multiple test cases. The first line contains tt (1≤t≤1051≤t≤105) — the number of test cases. Description of the test cases follows.
The first line of each test case contains three integers AA (1≤A≤1061≤A≤106), BB (1≤B≤1061≤B≤106) and nn (1≤n≤1051≤n≤105) — the attack power of the great hero, the initial health value of the great hero, and the number of monsters.
The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106), where aiai denotes the attack power of the ii-th monster.
The third line of each test case contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤1061≤bi≤106), where bibi denotes the initial health value of the ii-th monster.
It is guaranteed that the sum of nn over all test cases does not exceed 105105.
For each test case print the answer: "YES" (without quotes) if the great hero can kill all the monsters. Otherwise, print "NO" (without quotes).
5 3 17 1 2 16 10 999 3 10 20 30 100 50 30 1000 1000 4 200 300 400 500 1000 1000 1000 1000 999 999 1 1000 1000 999 999 1 1000000 999
YES YES YES NO YES
In the first example: There will be 66 fights between the hero and the only monster. After that, the monster is dead and the health value of the hero becomes 17−6×2=5>017−6×2=5>0. So the answer is "YES", and moreover, the hero is still living.
In the second example: After all monsters are dead, the health value of the hero will become 709709, regardless of the order of all fights. So the answer is "YES".
In the third example: A possible order is to fight with the 11-st, 22-nd, 33-rd and 44-th monsters. After all fights, the health value of the hero becomes −400−400. Unfortunately, the hero is dead, but all monsters are also dead. So the answer is "YES".
In the fourth example: The hero becomes dead but the monster is still living with health value 1000−999=11000−999=1. So the answer is "NO".
题目大意:我们的攻击力为A,血量为B,一共有n只野怪,第i只野怪的攻击力为ai,血量为bi,我们可以对任意一只野怪进行任意次数的攻击,每次攻击野怪会掉A的血,我们会掉ai的血,当血量小于0时会死亡,问我们能不能将所有野怪都消灭。可以同归于尽。
解题思路:由于可以同归于尽,我们可以将攻击力最高的野怪留到最后攻击,这样可以将血量的使用变为最优,如果当还差最后一击消灭攻击力最高的野怪时我们的血量还大于0,就说明我们可以消灭所有野怪。可以先假设将所有野怪都消灭,计算出消灭后的血量,再加上攻击力最高的野怪的攻击力,如果计算后的结果大于0就说明可以完全消灭·。
代码实现:
#include<cstdio> #include<algorithm> #include<cmath> #include<iostream> using namespace std; typedef long long ll; int main(){ int num; scanf("%d",&num); while(num--){ ll A,B,n; ll a[100000],b[100000]; ll maxx=-1,count,sum=0; scanf("%lld%lld%lld",&A,&B,&n); for(int i=0;i<n;i++){ scanf("%lld",&a[i]); maxx=max(maxx,a[i]); } for(int i=0;i<n;i++){ scanf("%lld",&b[i]); } for(int i=0;i<n;i++){ count=(b[i]+A-1)/A; sum+=count*a[i]; } B-=sum; B+=maxx; if(B>0) printf("YES\n"); else printf("NO\n"); } return 0; }