Codeforce Round 578 Div. 2 B. Block Adventure

B. Block Adventure

Problem

Gildong is playing a video game called Block Adventure. In Block Adventure, there are n columns of blocks in a row, and the columns are numbered from \(1\) to \(n\). All blocks have equal heights. The height of the \(i^{th}\) column is represented as \(h_i\), which is the number of blocks stacked in the \(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^{st}\) column. The goal of the game is to move the character to the top of the \(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^{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^{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^{th}\) column;
··if \(i < n\) and $ \left| h_i − h_{i + 1} \right| \leq k$, move the character to the top of the \((i+1)^{th}\) column. \(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^{th}\) column, and the value \(h_i\) changes.

The character initially has \(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.

Input

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

The first line of each test case contains three integers \(n, m, k (1 \leq n \leq 100, 0 \leq m \leq 10^6, 0 \leq k \leq 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 \(k\) described in the statement.

The second line of each test case contains \(n\) integers. The \(i^{th}\) integer is \(h_i (0 \leq hi \leq 10^6)\), the initial height of the \(i^{th}\) column.

Output

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

Example

input

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

output

YES
NO
YES
NO
YES

Note

In the first case, Gildong can take one block from the \(1^{st}\) column, move to the \(2^{nd}\) column, put the block on the \(2^{nd}\) column, then move to the \(3^{rd}\) column.

In the second case, Gildong has to put the block in his bag on the \(1^{st}\) column to get to the \(2^{nd}\) column. But it is impossible to get to the \(3^{rd}\) column because $ \left| h2−h3 \right| = 3 > k $and there is no way to decrease the gap.

In the fifth case, the character is already on the \(n^{th}\) column from the start so the game is won instantly.

想法

直接贪心拿掉当前所在位置所有的,然后放回去满足条件的最少的,看看手头上的数目是不是小于0即可

The Code Of My Program

/*********************
*@Author:   ChenShou *
*@Language: C++11    *
*********************/
//#include <bits/stdc++.h> 
#pragma comment(linker, "/STACK:102400000,102400000")
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
 
//#define DEBUG
#define RI register int
#define endl "\n"
 
using namespace std;
typedef long long ll;
//typedef __int128 lll;
//const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3f3f3f3f;
 
inline ll read(){
    long long x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f; 
}
 
 
int main()
{
#ifdef DEBUG
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
#endif
    //cout.tie(0);
    int t;
    scanf("%d",&t);
    while(t--){
    int n,m,k,flag=0;
    n=read(),m=read(),k=read();
    int bl[105]={0};
    for(int i=0;i<n;i++)bl[i]=read();
    bl[n]=bl[n-1];
    for(int i=0;i<n-1;i++){
        m+=bl[i];
        m-=max(bl[i+1]-k,0);
        if(m<0){
            flag=1;
            break;
        }
    }
    if(flag){
        printf("NO\n");
    }
    else printf("YES\n");
}
    //continue;
#ifdef DEBUG
    printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Fuck You !" << endl;
    return 0;
}

转载于:https://www.cnblogs.com/--ChenShou--/p/11356048.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值