309779: CF1734D. Slime Escape

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Slime Escape

题意翻译

在 $ n $ 个点的数轴上有一只 ${\color{black}{\text{S}}}{\color{red}{\text{lime}}}$,它在第 $ k $ 个点的位置,初始大小为 $ a_k $。 当史莱姆到达第 $ i $ 个点时,它的大小会加上 $ a_i $,如果它的大小为负数,它就死了。 请问史莱姆能否逃出数轴(即活着到达 $ 0 $ 或者 $ n + 1 $ 号点)。

题目描述

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 \le i \le n $ , the $ i $ -th slime is located at position $ i $ and has health $ a_i $ . 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?

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains a single integer $ t $ ( $ 1 \leq t \leq 20\,000 $ ) — 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 \leq n \leq 200\,000 $ , $ 1 \leq k \leq n $ ) — the number of slimes and the position of your slime. The second line of each test case contains $ n $ integers, $ a_1, a_2, \ldots, a_n $ ( $ -10^9 \leq a_i \leq 10^9 $ ) — the health of the slimes. It is guaranteed that health of your slime is non-negative ( $ a_k \geq 0 $ ), and all other slimes have non-zero health ( $ a_i \ne 0 $ for $ i \ne k $ ). It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 200\,000 $ .

输出格式


For each test case, print "YES" (without quotes) if you can escape without losing, and "NO" (without quotes) otherwise.

输入输出样例

输入样例 #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: 1. 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 $ . 2. Absorb the slimes at positions $ 3 $ , and $ 2 $ : your health becomes $ 7-7+10=10 $ . 3. Absorb the slime at position $ 8 $ : your health becomes $ 10-10=0 $ . 4. Use the escape at position $ 9 $ . Since your slime has maintained non-negative health at all times, you have won.

Input

题意翻译

在 $ n $ 个点的数轴上有一只 ${\color{black}{\text{S}}}{\color{red}{\text{lime}}}$,它在第 $ k $ 个点的位置,初始大小为 $ a_k $。 当史莱姆到达第 $ i $ 个点时,它的大小会加上 $ a_i $,如果它的大小为负数,它就死了。 请问史莱姆能否逃出数轴(即活着到达 $ 0 $ 或者 $ n + 1 $ 号点)。

Output

**史莱姆逃生**

**题意翻译**
在数轴上有 $ n $ 个点,有一只史莱姆(Slime)位于第 $ k $ 个点,初始大小为 $ a_k $。当史莱姆到达第 $ i $ 个点时,它的大小会加上 $ a_i $,如果它的大小变为负数,它就死了。问史莱姆能否逃出数轴(即活着到达 $ 0 $ 或者 $ n + 1 $ 号点)。

**题目描述**
你正在玩一个叫做“史莱姆逃生”的游戏。游戏发生在一个数轴上。最初,有 $ n $ 个史莱姆。对于所有满足 $ 1 \le i \le n $ 的正整数 $ i $,第 $ i $ 个史莱姆位于位置 $ i $,并且有健康值 $ a_i $。你正在控制位于位置 $ k $ 的史莱姆。

在位置 $ 0 $ 和 $ n+1 $ 有两个逃生点。你的目标是通过执行任意数量的游戏移动到达这两个逃生点中的任意一个。

在一次游戏移动中,你可以将你的史莱姆向左或向右移动一个位置。但是,如果新位置上还有另一个史莱姆,你必须吸收它。当吸收一个史莱姆时,你的史莱姆的健康值会增加被吸收史莱姆的健康值,然后被吸收的史莱姆会从游戏中移除。

请注意,一些史莱姆可能有负健康值,所以当你吸收这样的史莱姆时,你的健康值会减少。

如果游戏过程中你的史莱姆在任何时刻健康值为负,你会立即输掉游戏。

通过执行任意数量的游戏移动,能否在不输掉游戏的情况下到达两个逃生点之一?

**输入输出格式**
**输入格式**
每个测试包含多个测试用例。第一行包含一个整数 $ t $($ 1 \leq t \leq 20,000 $)——测试用例的数量。接下来是每个测试用例的描述。

每个测试用例的第一行包含两个正整数 $ n $,$ k $($ 3 \leq n \leq 200,000 $,$ 1 \leq k \leq n $)——史莱姆的数量和你的史莱姆的位置。

每个测试用例的第二行包含 $ n $ 个整数,$ a_1, a_2, \ldots, a_n $($ -10^9 \leq a_i \leq 10^9 $)——史莱姆的健康值。

保证你的史莱姆的健康值是非负的($ a_k \geq 0 $),并且所有其他史莱姆的健康值非零($ a_i \ne 0 $ 对于 $ i \ne k $)。

保证所有测试用例的 $ n $ 之和不超过 $ 200,000 $。

**输出格式**
对于每个测试用例,如果能逃走而不输掉游戏,则打印 "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
```

**说明**
在第一个测试用例中,你控制着位于位置 $ 4 $,健康值为 $ 6 $ 的史莱姆。逃生的方法之一是吸收位于位置 $ 5 $,$ 6 $,和 $ 7 $ 的史莱姆。你的史莱姆在位置 $ 8 $ 时以 $ 0 $ 的健康值逃生。

在第二个测试用例中,你控制着位于位置 $ 1 $,健康值为 $ 232 $ 的史莱姆。由于你的史莱姆已经位于靠近位置 $ 0 $ 的逃生点旁边,你可以不吸收任何史莱姆直接移动到那里。

在第三个测试用例中,可以证明你的史莱姆在到达任一两个逃生点之前总是会有负健康值。

在第四个测试用例中,你控制着位于位置 $ 4 $,健康值为 $ 6 $ 的史莱姆。以下描述了赢得游戏的可能移动顺序:

1. 吸收位于位置 $ 5 $,$ 6 $,和 $ 7 $ 的史**史莱姆逃生** **题意翻译** 在数轴上有 $ n $ 个点,有一只史莱姆(Slime)位于第 $ k $ 个点,初始大小为 $ a_k $。当史莱姆到达第 $ i $ 个点时,它的大小会加上 $ a_i $,如果它的大小变为负数,它就死了。问史莱姆能否逃出数轴(即活着到达 $ 0 $ 或者 $ n + 1 $ 号点)。 **题目描述** 你正在玩一个叫做“史莱姆逃生”的游戏。游戏发生在一个数轴上。最初,有 $ n $ 个史莱姆。对于所有满足 $ 1 \le i \le n $ 的正整数 $ i $,第 $ i $ 个史莱姆位于位置 $ i $,并且有健康值 $ a_i $。你正在控制位于位置 $ k $ 的史莱姆。 在位置 $ 0 $ 和 $ n+1 $ 有两个逃生点。你的目标是通过执行任意数量的游戏移动到达这两个逃生点中的任意一个。 在一次游戏移动中,你可以将你的史莱姆向左或向右移动一个位置。但是,如果新位置上还有另一个史莱姆,你必须吸收它。当吸收一个史莱姆时,你的史莱姆的健康值会增加被吸收史莱姆的健康值,然后被吸收的史莱姆会从游戏中移除。 请注意,一些史莱姆可能有负健康值,所以当你吸收这样的史莱姆时,你的健康值会减少。 如果游戏过程中你的史莱姆在任何时刻健康值为负,你会立即输掉游戏。 通过执行任意数量的游戏移动,能否在不输掉游戏的情况下到达两个逃生点之一? **输入输出格式** **输入格式** 每个测试包含多个测试用例。第一行包含一个整数 $ t $($ 1 \leq t \leq 20,000 $)——测试用例的数量。接下来是每个测试用例的描述。 每个测试用例的第一行包含两个正整数 $ n $,$ k $($ 3 \leq n \leq 200,000 $,$ 1 \leq k \leq n $)——史莱姆的数量和你的史莱姆的位置。 每个测试用例的第二行包含 $ n $ 个整数,$ a_1, a_2, \ldots, a_n $($ -10^9 \leq a_i \leq 10^9 $)——史莱姆的健康值。 保证你的史莱姆的健康值是非负的($ a_k \geq 0 $),并且所有其他史莱姆的健康值非零($ a_i \ne 0 $ 对于 $ i \ne k $)。 保证所有测试用例的 $ n $ 之和不超过 $ 200,000 $。 **输出格式** 对于每个测试用例,如果能逃走而不输掉游戏,则打印 "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 ``` **说明** 在第一个测试用例中,你控制着位于位置 $ 4 $,健康值为 $ 6 $ 的史莱姆。逃生的方法之一是吸收位于位置 $ 5 $,$ 6 $,和 $ 7 $ 的史莱姆。你的史莱姆在位置 $ 8 $ 时以 $ 0 $ 的健康值逃生。 在第二个测试用例中,你控制着位于位置 $ 1 $,健康值为 $ 232 $ 的史莱姆。由于你的史莱姆已经位于靠近位置 $ 0 $ 的逃生点旁边,你可以不吸收任何史莱姆直接移动到那里。 在第三个测试用例中,可以证明你的史莱姆在到达任一两个逃生点之前总是会有负健康值。 在第四个测试用例中,你控制着位于位置 $ 4 $,健康值为 $ 6 $ 的史莱姆。以下描述了赢得游戏的可能移动顺序: 1. 吸收位于位置 $ 5 $,$ 6 $,和 $ 7 $ 的史

加入题单

算法标签: