CF1200B.Block Adventure

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Gildong is playing a video game called Block Adventure. In Block Adventure, there are nn columns of blocks in a row, and the columns are numbered from 11 to nn. All blocks have equal heights. The height of the ii-th column is represented as hih_i, which is the number of blocks stacked in the ii-th column.

Gildong plays the game as a character that can stand only on the top of the columns. At the beginning, the character is standing on the top of the 11-st column. The goal of the game is to move the character to the top of the nn-th column.

The character also has a bag that can hold infinitely many blocks. When the character is on the top of the ii-th column, Gildong can take one of the following three actions as many times as he wants:

  • if there is at least one block on the column, remove one block from the top of the ii-th column and put it in the bag;
  • if there is at least one block in the bag, take one block out of the bag and place it on the top of the ii-th column;
  • if i<ni \lt n and ∣hi−hi+1∣≤k|h_i - h_{i+1}| \le k, move the character to the top of the i+1i+1-st column. kk is a non-negative integer given at the beginning of the game. Note that it is only possible to move to the next column.

In actions of the first two types the character remains in the ii-th column, and the value hih_i changes.

The character initially has mm blocks in the bag. Gildong wants to know if it is possible to win the game. Help Gildong find the answer to his question.

吉尔东正在玩一款名为“方块冒险”的视频游戏。在“方块冒险”中,一行排列着 nn 列方块,列从 11 编号到 nn。所有方块高度相等。第 ii 列的高度记为 hih_i,即该列堆叠的方块数量。

吉尔东以一个角色进行游戏,该角色只能站在各列的顶端。初始时,角色位于第 11 列的顶端。游戏目标是将角色移动至第 nn 列的顶端。

该角色还携带一个可容纳无限多个方块的背包。当角色位于第 ii 列顶端时,吉尔东可任意多次执行以下三种操作之一:

  • 若该列至少有一个方块,则从第 ii 列顶端移除一个方块,并将其放入背包;
  • 若背包中至少有一个方块,则从背包中取出一个方块,并将其放置于第 ii 列顶端;
  • 若 i<ni \lt n 且 ∣hi−hi+1∣≤k|h_i - h_{i+1}| \le k,则将角色移动至第 i+1i+1 列顶端。其中 kk 是游戏开始时给定的一个非负整数。注意:角色仅能向下一列移动。

在前两类操作中,角色始终停留在第 ii 列,且 hih_i 的值会随之改变。

角色初始时背包中有 mm 个方块。吉尔东想知道是否能够赢得游戏。请帮助吉尔东判断这个问题的答案。

输入格式

Each test contains one or more test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). Description of the test cases follows.

The first line of each test case contains three integers nn, mm, and kk (1≤n≤1001 \le n \le 100, 0≤m≤1060 \le m \le 10^6, 0≤k≤1060 \le k \le 10^6) — the number of columns in the game, the number of blocks in the character's bag at the beginning, and the non-negative integer kk described in the statement.

The second line of each test case contains nn integers. The ii-th integer is hih_i (0≤hi≤1060 \le h_i \le 10^6), the initial height of the ii-th column.

每个测试包含一个或多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。随后是测试用例的描述。

每个测试用例的第一行包含三个整数 nn、mm 和 kk(1≤n≤1001 \le n \le 100,0≤m≤1060 \le m \le 10^6,0≤k≤1060 \le k \le 10^6)——分别表示游戏中的列数、角色初始背包中的方块数量,以及题目描述中所述的非负整数 kk。

每个测试用例的第二行包含 nn 个整数。其中第 ii 个整数为 hih_i(0≤hi≤1060 \le h_i \le 10^6),表示第 ii 列的初始高度。

输出格式

For each test case, print "YES" if it is possible to win the game. Otherwise, print "NO".

You can print each letter in any case (upper or lower).

对于每个测试用例,如果可以赢得游戏,则输出 “YES”;否则输出 “NO”。

你可以以任意大小写(大写或小写)输出每个字母。

输入输出样例

  • 输入#1

    5
    3 0 1
    4 3 5
    3 1 2
    1 4 7
    4 10 0
    10 20 10 20
    2 5 5
    0 11
    1 9 9
    99

    输出#1

    YES
    NO
    YES
    NO
    YES

说明/提示

In the first case, Gildong can take one block from the 11-st column, move to the 22-nd column, put the block on the 22-nd column, then move to the 33-rd column.

In the second case, Gildong has to put the block in his bag on the 11-st column to get to the 22-nd column. But it is impossible to get to the 33-rd column because ∣h2−h3∣=3>k|h_2 - h_3| = 3 \gt k and there is no way to decrease the gap.

In the fifth case, the character is already on the nn-th column from the start so the game is won instantly.

在第一种情况下,吉尔东可以从第 11 列取走一个方块,移动到第 22 列,将该方块放置在第 22 列上,然后移动到第 33 列。

在第二种情况下,吉尔东必须先将手中背包里的方块放在第 11 列,才能到达第 22 列。但此时无法到达第 33 列,因为 ∣h2−h3∣=3>k|h_2 - h_3| = 3 \gt k,且无法缩小这一高度差。

在第五种情况下,角色初始位置即为第 nn 列,因此游戏立即获胜。

输入解题思路,AI测评打分。不知道怎么写?

首页