zoukankan      html  css  js  c++  java
  • B . Block Adventure (贪心+模拟 )

    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 hihi, 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<n and |hihi+1|k|hi−hi+1|≤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 hihi 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.

    Input

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

    The first line of each test case contains three integers nn, mm, and kk (1n1001≤n≤100, 0m1060≤m≤106, 0k1060≤k≤106) — 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 hihi (0hi1060≤hi≤106), the initial height of the ii-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 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 |h2h3|=3>k|h2−h3|=3>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.

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    typedef long long lli;
    using namespace std;
    const int  mxn = 1e9;
    #define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
    multiset<int> v;
    multiset<int> :: iterator it ;
    int a[100+5];
    
    int main()
    {
        TLE;
        int t,n,cnt=1,m,k,l,x;
        cin>>t;
        while(t--)
        {
            cin>>n>>m>>k;
            cin>>x;
            int flag=0;
            for(int i=1;i<n;i++)
            {
                cin>>l;
                if(!flag)
                {
                    if(x+m<l-k)
                        flag=1;
                    else
                    {
                        if(l-k>=0)
                            m = (x+m) - (l-k);
                        else
                            m = (x+m);
                        x = l;
                    }
                }
            }
            if(flag) 
            cout<<"NO"<<endl; else cout<<"YES"<<endl; } return 0; }
    所遇皆星河
  • 相关阅读:
    23种设计模式中的模板模式
    23种设计模式中的外观模式
    div,li,span自适应宽度换行问题
    监听自定义ItemRender的事件
    flex acionscript png图片去除多余空白,生成合适大小图片
    项目中用到RouteTable,发布到IIS7中无法访问
    记录Castle ActiveRecord访问Sqlite的配置
    如何卸载软件
    linux 下route命令
    linux 下 ifcfg-eth0 配置 以及ifconfig、ifup、ifdown区别
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11623505.html
Copyright © 2011-2022 走看看