• 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} ight| 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 ight| = 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 "
    "
     
    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
    ");
        }
        else printf("YES
    ");
    }
        //continue;
    #ifdef DEBUG
        printf("Time cost : %lf s
    ",(double)clock()/CLOCKS_PER_SEC);
    #endif
        //cout << "Fuck You !" << endl;
        return 0;
    }
    
  • 相关阅读:
    事件对象3
    事件对象2
    事件对象1
    编码、摘要、加密
    身份证号码的组成
    Oracle的TO_CHAR()格式化数字为百分数的字符串
    转载和补充:Oracle中的一些特殊字符
    linux Shell(待学)
    linux 管道相关命令(待学)
    linux用户权限、系统信息相关命令(待学)
  • 原文地址:https://www.cnblogs.com/--ChenShou--/p/11356048.html
Copyright © 2020-2023  润新知