CF1734D.Slime Escape
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are playing a game called Slime Escape. The game takes place on a number line. Initially, there are n slimes. For all positive integers i where 1≤i≤n, the i-th slime is located at position i and has health ai. You are controlling the slime at position k.
There are two escapes located at positions 0 and n+1. Your goal is to reach any one of the two escapes by performing any number of game moves.
In one game move, you move your slime to the left or right by one position. However, if there is another slime in the new position, you must absorb it. When absorbing a slime, the health of your slime would be increased by the health of the absorbed slime, then the absorbed slime would be removed from the game.
Note that some slimes might have negative health, so your health would decrease when absorbing such slimes.
You lose the game immediately if your slime has negative health at any moment during the game.
Can you reach one of two escapes by performing any number of game moves, without ever losing the game?
你正在玩一款名为“史莱姆逃脱”的游戏。游戏在一个数轴上进行。初始时,共有 n 个史莱姆。对所有满足 1≤i≤n 的正整数 i,第 i 个史莱姆位于位置 i,其生命值为 ai。你控制着位于位置 k 的史莱姆。
在位置 0 和 n+1 处各有一个出口。你的目标是通过任意次数的游戏操作,抵达其中任一出口。
一次游戏操作中,你可以将你控制的史莱姆向左或向右移动一个单位距离。但如果新位置上存在另一个史莱姆,则你必须吸收它。吸收一个史莱姆后,你控制的史莱姆的生命值会增加被吸收史莱姆的生命值,随后被吸收的史莱姆将从游戏中移除。
注意:某些史莱姆的生命值可能为负数,因此吸收这类史莱姆会导致你的生命值减少。
若在游戏过程中的任意时刻,你控制的史莱姆生命值变为负数,则你立即失败。
你能否通过任意次数的游戏操作,在不失败的前提下抵达两个出口之一?
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤20000) — the number of test cases. Description of the test cases follows.
The first line of each test case contains two positive integers n, k (3≤n≤200000, 1≤k≤n) — the number of slimes and the position of your slime.
The second line of each test case contains n integers, a1,a2,…,an (−109≤ai≤109) — the health of the slimes.
It is guaranteed that health of your slime is non-negative (ak≥0), and all other slimes have non-zero health (ai=0 for i=k).
It is guaranteed that the sum of n over all test cases does not exceed 200000.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤20000),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个正整数 n、k(3≤n≤200000,1≤k≤n),分别表示史莱姆的总数以及你的史莱姆的位置。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(−109≤ai≤109),表示各史莱姆的生命值。
保证你的史莱姆的生命值非负(即 ak≥0),且其余所有史莱姆的生命值均不为零(即对所有 i=k,有 ai=0)。
保证所有测试用例的 n 值之和不超过 200000。
输出格式
For each test case, print "YES" (without quotes) if you can escape without losing, and "NO" (without quotes) otherwise.
对于每个测试用例,如果你能在不失败的情况下逃脱,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。
输入输出样例
输入#1
6 7 4 -1 -2 -3 6 -2 -3 -1 3 1 232 -500 -700 7 4 -1 -2 -4 6 -2 -4 -1 8 4 -100 10 -7 6 -2 -3 6 -10 8 2 -999 0 -2 3 4 5 6 7 7 3 7 3 3 4 2 1 1
输出#1
YES YES NO YES NO YES
说明/提示
In the first test case, you control the slime at position 4 with health 6. One way to escape is to absorb the slimes at positions 5, 6, and 7. Your slime escapes with 0 health at position 8.
In the second test case, you control the slime with 232 health at position 1. Since your slime is already located next to the escape at position 0, you can move to it without absorbing any slime.
In the third test case, it can be shown that your slime would always have a negative health before reaching any one of two escapes.
In the fourth test case, you control the slime at position 4 with health 6. The following describes a possible sequence of moves to win:
- Absorb the slimes at positions 5, 6, and 7: your health becomes 4 after absorbing the slime with health −2; becomes 1 after absorbing the slime with health −3; and becomes 7 after absorbing the slime with health 6.
- Absorb the slimes at positions 3, and 2: your health becomes 7−7+10=10.
- Absorb the slime at position 8: your health becomes 10−10=0.
- Use the escape at position 9.
Since your slime has maintained non-negative health at all times, you have won.
在第一个测试用例中,你控制位于位置 4、生命值为 6 的史莱姆。一种逃脱方式是吸收位置 5、6 和 7 处的史莱姆。你的史莱姆最终以 0 点生命值抵达位置 8 并成功逃脱。
在第二个测试用例中,你控制位于位置 1、生命值为 232 的史莱姆。由于你的史莱姆已紧邻位于位置 0 的出口,因此无需吸收任何史莱姆即可直接移动至出口。
在第三个测试用例中,可以证明:无论采取何种策略,你的史莱姆在抵达任一出口(共两个)之前,生命值总会变为负数。
在第四个测试用例中,你控制位于位置 4、生命值为 6 的史莱姆。以下是一种可行的获胜操作序列:
- 吸收位置 5、6 和 7 处的史莱姆:吸收生命值为 −2 的史莱姆后,你的生命值变为 4;再吸收生命值为 −3 的史莱姆后,生命值变为 1;最后吸收生命值为 6 的史莱姆后,生命值变为 7。
- 吸收位置 3 和 2 处的史莱姆:你的生命值变为 7−7+10=10。
- 吸收位置 8 处的史莱姆:你的生命值变为 10−10=0。
- 使用位于位置 9 的出口。
由于你的史莱姆在整个过程中生命值始终非负,因此你获胜。
输入解题思路,AI测评打分。不知道怎么写?