传送门

有必要提醒自己一下, 先把题读利索了(手动捂脸)


题目

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

Input

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.

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

Example
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
1000000
999
output
YES
YES
YES
NO
YES
Note

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只怪物。
下面2行, 每行n个值, 表示第i个怪物有攻击力ai和初始生命值bi。
在每场战斗中,英雄可以任意选择一个活着的怪物并与之战斗。1 vs 1
假设第i个怪物被选中,英雄和第i个怪物血量x和y --> x−ai和y−A。
注意,英雄可以多次对抗同一个怪物。
为了国家人民的安全,请告诉他们大英雄是否能杀死所有的怪物(即使大英雄杀死最后一个怪物后自己也死了)。

数据范围:A,B,a(i),b(i)<=1e6 ,n<=1e5


思路

最后一次攻击前, 英雄血量>0, 就成功了  ===> 最后抵御最大攻击前, 英雄血量 > 0

AC代码

 1 #include <iostream>
2 #include <algorithm>
3
4 using namespace std;
5
6 typedef long long ll;
7
8 const int N = 1e5 + 10;
9
10 ll tar1[N], blood1[N], res, tar, blood;
11
12 int main()
13 {
14 int t;
15 scanf("%d", &t);
16 while(t--)
17 {
18 int n;
19 scanf("%lld%lld%d", &tar, &blood, &n);
20
21 for(int i = 0; i < n ; i++) scanf("%lld", &tar1[i]);
22 for(int i = 0; i < n ; i++) scanf("%lld", &blood1[i]);
23
24 res = 0;
25 ll maxn = -1;
26 for(int i = 0; i < n ; i++)
27 {
28 int sum = blood1[i] / tar + (blood1[i] % tar != 0);
29 res += sum * tar1[i];
30 maxn = max(maxn, tar1[i]);
31 }
32
33 if(res - maxn >= blood)
34 printf("NO\n");
35 else
36 printf("YES\n");
37 }
38
39 return 0;
40 }

Codeforces Round #700 (Div. 2) --- B(思维)的更多相关文章

  1. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

  2. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  3. Codeforces Round #395 (Div. 2)(A.思维,B,水)

    A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  4. Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)

    A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  5. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

  6. Codeforces Round #539 (Div. 2) D 思维

    https://codeforces.com/contest/1113/problem/D 题意 将一个回文串切成一段一段,重新拼接,组成一个新的回文串,问最少切几刀 题解 首先无论奇偶串,最多只会切 ...

  7. Codeforces Round #542(Div. 2) CDE 思维场

    C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...

  8. Codeforces Round #304 (Div. 2) D 思维/数学/质因子/打表/前缀和/记忆化

    D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  9. Codeforces Round #619 (Div. 2)E思维+二维RMQ

    题:https://codeforces.com/contest/1301/problem/E 题意:给个n*m的图形,q个询问,每次询问问询问区间最大的合法logo的面积是多少 分析:由于logo是 ...

随机推荐

  1. Anaconda环境配置

    镜像下载.域名解析.时间同步请点击 阿里巴巴开源镜像站 前言 Anaconda环境配置 Anaconda安装完后要进行环境配置,环境配置就是安装虚拟环境,让程序可以在这个环境中运行! 一.Anacon ...

  2. PCI协议 总结

    1.引脚 必要的引脚在左边,任选的引脚在右边 2.CLK in:时钟输入,为所有PCI上的接口传送提供时序.其频率也称为PCI的工作频率. 大部分信号都在CLK的上升沿有效 3.AD0~AD31 t/ ...

  3. 寻路算法之A*算法详解

    前言 在实际开发中我们会经常用到寻路算法,例如MMOARPG游戏魔兽中,里面的人物行走为了模仿真实人物行走的体验,会选择最近路线达到目的地,期间会避开高山或者湖水,绕过箱子或者树林,直到走到你所选定的 ...

  4. Python库国内镜像

    中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ http://pypi.mirrors.ustc.edu.cn/simple/ 豆瓣 http://py ...

  5. J20航模遥控器开源项目系列教程(五)| 制作STM32F0接收机,8路PWM输出,SBUS输出,PPM输出 | 加密狗无线化,畅玩飞行模拟器

    我们的开源宗旨:自由 协调 开放 合作 共享 拥抱开源,丰富国内开源生态,开展多人运动,欢迎加入我们哈~ 和一群志同道合的人,做自己所热爱的事! 项目开源地址:https://github.com/J ...

  6. Flutter入门教程(一)Flutter简介

    这是Flutter系列第一篇文章,后续会持续更新Flutter相关知识,本篇就主要对于Flutter技术做一个简单的入门介绍 一.Flutter简介 Flutter是谷歌的移动UI框架,可以快速在iO ...

  7. 什么是 CSRF 攻击?

    CSRF 代表跨站请求伪造.这是一种攻击,迫使最终用户在当前通过身份验证的 Web 应用程序上执行不需要的操作.CSRF 攻击专门针对状态改变请求,而不是 数据窃取,因为攻击者无法查看对伪造请求的响应 ...

  8. django模板之forloop

    在django的模板中,有forloop这一模板变量,颇似php Smarty中的foreach.customers, Smarty foreach如下: {foreach name=customer ...

  9. 初识Spring(为什么要使用Spring?)

    Spring,英文翻译是春天的意思,而在Java中,是一个开放源代码的设计层面框架(手动滑稽,程序员的春天),他解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用.S ...

  10. 【Python自动化Excel】Python与pandas字符串操作

    Python之所以能够成为流行的数据分析语言,有一部分原因在于其简洁易用的字符串处理能力. Python的字符串对象封装了很多开箱即用的内置方法,处理单个字符串时十分方便:对于Excel.csv等表格 ...