当前位置:   article > 正文

Codeforces Round #700 (Div. 2)-B. The Great Hero-题解-一行实现向上取整_codeforces 700 div2

codeforces 700 div2

Codeforces Round #700 (Div. 2)-B. The Great Hero

传送门
Time Limit: 2 seconds
Memory Limit: 512 megabytes

Problem Description

The great hero guards the country where Homer lives. The hero has attack power A A A and initial health value B B B. There are n n n monsters in front of the hero. The i i i-th monster has attack power a i a_i ai and initial health value b i b_i bi.

The hero or a monster is said to be living, if his or its health value is positive (greater than or equal to 1 1 1); and he or it is said to be dead, if his or its health value is non-positive (less than or equal to 0 0 0).

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.**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).

Input

Each test contains multiple test cases. The first line contains t t t ( 1 ≤ t ≤ 1 0 5 1 \le t \le 10^5 1t105) — the number of test cases. Description of the test cases follows.

The first line of each test case contains three integers A A A ( 1 ≤ A ≤ 1 0 9 1 \leq A \leq 10^9 1A109), B B B ( 1 ≤ B ≤ 1 0 9 1 \leq B \leq 10^9 1B109) and n n n ( 1 ≤ n ≤ 1 0 5 1 \leq n \leq 10^5 1n105) — 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 n n n integers a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,,an ( 1 ≤ a i ≤ 1 0 9 1 \leq a_i \leq 10^9 1ai109), where a i a_i ai denotes the attack power of the i i i-th monster.

The third line of each test case contains n n n integers b 1 , b 2 , … , b n b_1, b_2, \dots, b_n b1,b2,,bn ( 1 ≤ b i ≤ 1 0 9 1 \leq b_i \leq 10^9 1bi109), where b i b_i bi denotes the initial health value of the i i i-th monster.

It is guaranteed that the sum of n n n over all test cases does not exceed 1 0 5 10^5 105.

Output

For each test case print the answer: “YES” (without quotes) if the great hero can kill all the monsters. Otherwise, print “NO” (without quotes).

Sample Input

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
1000000000
999
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

Sample Onput

YES
YES
YES
NO
YES
  • 1
  • 2
  • 3
  • 4
  • 5

Note

In the first example: There will be 6 6 6 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 > 0 17 - 6 \times 2 = 5 > 0 176×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 709 709 709, regardless of the order of all fights. So the answer is “YES”.

In the third example: A possible order is to fight with the 1 1 1-st, 2 2 2-nd, 3 3 3-rd and 4 4 4-th monsters. After all fights, the health value of the hero becomes − 400 -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 = 1 1000 - 999 = 1 1000999=1. So the answer is “NO”.


题目大意

英雄 A A A攻击 B B B滴血
小怪 i i i a i a_i ai的攻击和 b i b_i bi的血
每次英雄有选择的单挑,问英雄能不能杀死所有的怪


注意事项

问的是能不能杀死所有的怪,没有说英雄一定要活着,最后可能同归于尽

伤害是1e9级别,多个伤害叠加可能超过int范围(我这这里错了好多次)


解题思路

最后杀哪个怪?
当然是最后杀攻击最高的怪。
因为杀了这个怪可能就同归了,如果先杀攻击高的怪,可能其他小怪还没杀就和这个大怪同归了。

最后一刀给攻击最高的怪,如何计算最后一刀之前英雄血量的状态呢?
相当于先打败所有怪,再把最后一刀掉的血加上(加上一个最高伤害)

最后一刀之前,只有英雄还活着,它就能杀出这最后一刀,即为杀死所有的小怪。

哪怕中途英雄已经死了,也不影响最终的判断。


AC代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct gs //怪兽
{
	ll a, b; //a是血量,b是伤害(攻击)
} mon[100010];
int main()
{
	ll N;
	cin >> N;
	while (N--)
	{
		ll A, B, n;
		scanf("%lld%lld%lld", &A, &B, &n); //英雄血量、英雄伤害、小怪数量
		ll Msh = 0;						   // 来记录小怪的最大伤害
		for (ll i = 0; i < n; i++)
		{
			scanf("%lld", &mon[i].a);
			Msh = max(Msh, mon[i].a); //更新小怪的最大伤害
		}
		for (ll i = 0; i < n; i++)
		{
			scanf("%lld", &mon[i].b);
		}
		for (ll i = 0; i < n; i++)
		{
			//times是需要攻击这个小怪的次数
			ll times = mon[i].b / A + (mon[i].b % A != 0);
			/*times
				首先times=mon[i].b/A是向下取整
				接下来如果(mon[i].b % A != 0),则括号里为true(1),正好为向上取整
			*/
			B -= times * mon[i].a; //减去英雄受到的伤害
		}
		B += Msh; //恢复到最后一刀之前的状态
		puts(B <= 0 ? "NO" : "YES"); //英雄血量B  小于0吗?  如果是,puts("NO")   否则,puts("YES")
	}
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/506316
推荐阅读
相关标签
  

闽ICP备14008679号