题意翻译

题目描述

你在玩一个游戏,已知在你面前有nnn列砖块,你的背包中有mmm个砖块,第iii列有hih_ihi个砖块。

在第iii列你可以进行下列操作

  • 如果你的背包中有砖块,你可以将将背包中的砖块放在第iii列。
  • 如果第iii列有砖块,你可以捡起来,放在背包中。
  • 如果第iii列和第i+1i+1i+1列的高度差少于或等于kkk个砖块,你可以从第iii列跳到第i+1i+1i+1列。

问你是否能从第一列从第111列跳到第nnn列。 如果能,输出YESYESYES,如果不能,输出NONONO。。

输入格式

多组测试数据

第一行输入组数T(1≤T≤1000){T}(1{\le}T{\le}1000)T(1T1000)

对于每组测试数据

第一行输入n,m,k(1≤n≤100,0≤m≤106,0≤k≤106)n,m,k({1{\le}n{\le}100},{0{\le}m{\le}10^6},{0{\le}k{\le}10^6})n,m,k(1n100,0m106,0k106)

第二行输入nnn个数,第iii个数代表hih_ihi

输出格式

对于每组数据,输出YESYESYESNONONO

题目描述

Gildong is playing a video game called Block Adventure. In Block Adventure, there are n n n columns of blocks in a row, and the columns are numbered from 1 1 1 to n n n . All blocks have equal heights. The height of the i i i -th column is represented as hi h_i hi , which is the number of blocks stacked in the i i i -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 1 1 1 -st column. The goal of the game is to move the character to the top of the n n n -th column.

The character also has a bag that can hold infinitely many blocks. When the character is on the top of the i i i -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 i i i -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 i i i -th column;
  • if i<n i < n i<n and ∣hi−hi+1∣≤k |h_i - h_{i+1}| \le k hihi+1k , move the character to the top of the i+1 i+1 i+1 -st column. k k k 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 i i i -th column, and the value hi h_i hi changes.

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

输入格式

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

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

The second line of each test case contains n n n integers. The i i i -th integer is hi h_i hi ( 0≤hi≤106 0 \le h_i \le 10^6 0hi106 ), the initial height of the i i i -th column.

输出格式

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

输入输出样例

输入 #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 1 1 1 -st column, move to the 2 2 2 -nd column, put the block on the 2 2 2 -nd column, then move to the 3 3 3 -rd column.

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

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

#include <bits/stdc++.h>

using namespace std ;

int T , n , m , k , a[120] ;

int main () {

	cin >> T ;

	while(T --) {

		cin >> n >> m >> k ;

		for(int i = 1 ; i <= n ; i ++) {

			cin >> a[i] ;

		}

		int flag = 1 ;

		/*for(int i = 1 ; i < n && flag ; i ++) { if(a[i] >= a[i+1]-k) { m += (a[i]-a[i+1]+k,a[i]) ; }else { m -= a[i+1]-a[i]-k ; a[i] = a[i+1] - k ; } if(m < 0) flag = 0 ; }*/
		for (int now=1;now<n&&flag;now++){
               if (a[now]>=a[now+1]-k)m+=min(a[now]-a[now+1]+k,a[now]);
                else m-=a[now+1]-a[now]-k,a[now]=a[now+1]-k;
                if (m<0)flag=0;
                }

		puts(flag?"YES":"NO") ;

	}

	return 0 ;

}