CF1923B.Monsters Attack!
普及-
通过率:0%
时间限制:2.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are playing a computer game. The current level of this game can be modeled as a straight line. Your character is in point 0 of this line. There are n monsters trying to kill your character; the i-th monster has health equal to ai and is initially in the point xi.
Every second, the following happens:
- first, you fire up to k bullets at monsters. Each bullet targets exactly one monster and decreases its health by 1. For each bullet, you choose its target arbitrary (for example, you can fire all bullets at one monster, fire all bullets at different monsters, or choose any other combination). Any monster can be targeted by a bullet, regardless of its position and any other factors;
- then, all alive monsters with health 0 or less die;
- then, all alive monsters move 1 point closer to you (monsters to the left of you increase their coordinates by 1, monsters to the right of you decrease their coordinates by 1). If any monster reaches your character (moves to the point 0), you lose.
Can you survive and kill all n monsters without letting any of them reach your character?
你正在玩一款电脑游戏。当前关卡可以建模为一条直线。你的角色位于该直线上的点 0 处。有 n 只怪物试图击杀你的角色;第 i 只怪物的生命值为 ai,初始位置为 xi。
每秒内,依次发生以下事件:
- 首先,你最多可发射 k 发子弹攻击怪物。每发子弹恰好瞄准一只怪物,并使其生命值减少 1。对于每发子弹,你可以任意选择其目标(例如,可将全部子弹射向同一只怪物,也可分别射向不同的怪物,或采用其他任意组合)。任何怪物均可被选为目标,不受其位置或其他因素限制;
- 接着,所有生命值 ≤0 的存活怪物立即死亡;
- 然后,所有仍存活的怪物向你移动 1 个单位(位于你左侧(即坐标为负)的怪物坐标加 1,位于你右侧(即坐标为正)的怪物坐标减 1)。若有任何怪物抵达你的角色所在位置(即移动至点 0),则你失败。
你能否在不让任何怪物抵达点 0 的前提下存活并消灭全部 n 只怪物?
输入格式
The first line of the input contains one integer t (1≤t≤3⋅104) — the number of test cases.
Each test case consists of three lines:
- the first line contains two integers n and k (1≤n≤3⋅105; 1≤k≤2⋅109);
- the second line contains n integers a1,a2,…,an (1≤ai≤109);
- the third line contains n integers x1,x2,…,xn (−n≤x1<x2<x3<⋯<xn≤n; xi=0).
Additional constraint on the input: the sum of n over all test cases does not exceed 3⋅105.
输入的第一行包含一个整数 t(1≤t≤3⋅104),表示测试用例的数量。
每个测试用例由三行组成:
- 第一行包含两个整数 n 和 k(1≤n≤3⋅105;1≤k≤2⋅109);
- 第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109);
- 第三行包含 n 个整数 x1,x2,…,xn(−n≤x1<x2<x3<⋯<xn≤n;且 xi=0)。
输入的额外约束:所有测试用例的 n 值之和不超过 3⋅105。
输出格式
For each test case, print YES if you can kill all n monsters before they reach your character, or NO otherwise.
You can output each letter of the answer in any case (upper or lower). For example, the strings yEs, yes, Yes, and YES will all be recognized as positive responses.
对于每个测试用例,若能在所有 n 个怪物抵达你的角色之前将其全部消灭,则输出 YES;否则输出 NO。
答案的每个字母可为任意大小写(大写或小写)。例如,字符串 yEs、yes、Yes 和 YES 均会被识别为肯定回答。
输入输出样例
输入#1
5 3 2 1 2 3 -1 2 3 2 1 1 1 -1 1 4 10 3 4 2 5 -3 -2 1 3 5 3 2 1 3 2 5 -3 -2 3 4 5 2 1 1 2 1 2
输出#1
YES NO YES YES NO
说明/提示
In the first example, you can act as follows:
- during the 1-st second, fire 1 bullet at the 1-st monster and 1 bullet at the 3-rd monster. Then the 1-st monster dies, the 2-nd and the 3-rd monster move closer;
- during the 2-nd second, fire 2 bullets at the 2-nd monster. Then the 2-nd monster dies, the 3-rd monster moves closer;
- during the 3-rd second, fire 2 bullets at the 3-rd monster. Then the 3-rd monster dies.
In the second example, you can fire only 1 bullet, so you can kill only one of the two monsters during the 1-st second. Then, the remaining monster moves closer and kills your character.
在第一个例子中,你可以按如下方式行动:
- 在第 1 秒,向第 1 个怪物发射 1 发子弹,同时向第 3 个怪物发射 1 发子弹。此时第 1 个怪物死亡,第 2 个和第 3 个怪物向你靠近;
- 在第 2 秒,向第 2 个怪物发射 2 发子弹。此时第 2 个怪物死亡,第 3 个怪物向你靠近;
- 在第 3 秒,向第 3 个怪物发射 2 发子弹。此时第 3 个怪物死亡。
在第二个例子中,你每秒只能发射 1 发子弹,因此在第 1 秒你只能杀死两个怪物中的一个。随后,剩余的怪物向你靠近并杀死你的角色。
输入解题思路,AI测评打分。不知道怎么写?