原题链接:

添加链接描述

题意:

You have n stacks of blocks. The i-th stack contains hi blocks and it’s height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i+1-th stack. Can you make the sequence of heights strictly increasing?

Note that the number of stacks always remains n: stacks don’t disappear when they have 0 blocks.

Input

First line contains a single integer t (1≤t≤104) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤100). The second line of each test case contains n integers hi (0≤hi≤109) — starting heights of the stacks.

It’s guaranteed that the sum of all n does not exceed 104.

Output

For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.

You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

Example

input

6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000

output

YES
YES
YES
NO
NO
YES

Note

In the first test case there is no need to make any moves, the sequence of heights is already increasing.

In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.

In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.

In the fourth test case we can’t make a move, but the sequence is not increasing, so the answer is NO.

In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO.

题解:

本题是让找出在所有的石头堆是否可以排成一个长度为n的一个递增的堆列,
我们可以每一次都将前面比i多出来的石头拿出来放到后面,每次判断上次多出来的加上它本来的石头是否>i,如果小于就输出“NO”,否则的话输出“YES”。

代码:

#include<iostream>
using namespace std;int a[105];
int main()
{int t;cin>>t;while(t--){int n;cin>>n;for(int i=0;i<n;i++)cin>>a[i];long long int dp=0;int f=0;for(int i=0;i<n;i++){if(dp+a[i]<i){cout<<"NO"<<endl;f=1;break;}dp+=(a[i]-i);a[i]-=i;}if(f==0)cout<<"YES"<<endl;}
}

A. Shifting Stacks相关推荐

  1. Codeforces Round #703 (Div. 2)A. Shifting Stacks

    A. Shifting Stacks time limit per test1 second memory limit per test256 megabytes inputstandard inpu ...

  2. Shifting Stacks【题解】

    Codeforces Round #703 (Div. 2)A. Shifting Stacks## 问题描述: A. Shifting Stacks time limit per test1 sec ...

  3. Codeforces Round #703 (Div. 2)(A ~ F)超高质量题解【每日亿题2 / 19】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A. Shifting Stacks B - Eastern Exhibition C1 - G ...

  4. Codeforces Round #703 (Div. 2)

    Codeforces Round #703 (Div. 2) 题号 题目 知识点 A Shifting Stacks 思维 B Eastern Exhibition 思维 C1 Guessing th ...

  5. Codeforces Round #703 (Div. 2) 题解

    文章目录 A. Shifting Stacks B. Eastern Exhibition C. Guessing the Greatest D. Max Median E. Paired Payme ...

  6. Codeforces Round #703 (Div. 2) A-E 题解

    Shifting Stacks 给你 n 长度的数组,每个下标包含 000-nnn 个木块 其中可以将某一位置的木块向右边平移 请问是否能凑出高度严格上升的数组 一开始想简单了 直接判断木块的和是否大 ...

  7. LeetCode刷题记录12——232. Implement Queue using Stacks(easy)

    LeetCode刷题记录12--232. Implement Queue using Stacks(easy) 目录 LeetCode刷题记录12--232. Implement Queue usin ...

  8. Docker 入门(Mac环境)- part 5 stacks

    part-5 stacks 简介 stack就是栈,栈的结构是什么样的呢?一层一层是紧挨着的,然后互相依赖,不能说中间少了一个.这样说就很明白了,栈实际上在docker中就相当于多个互相依赖的组件,共 ...

  9. C++ Stacks(堆栈)

    C++Stacks(堆栈) 操作 empty pop push size top 操作 语法: == <= = < != 所有的这些操作可以被用于堆栈. 相等指堆栈有相同的元素并有着相同的 ...

最新文章

  1. dataframe sample 采样,抽样
  2. java中判断Object对象类型
  3. 零样本性能超越GPT-3!谷歌提出1370亿参数自回归语言模型
  4. ubuntu18.04.4 LTS 安装NVIDIA驱动亲测有用方法2020年最新及常见问题避坑
  5. android双联动列表,Android Fragment实现列表和内容联动
  6. mysql 5.7 ddl 原子_mysql 8 新特性二DDL操作的原子化
  7. Xcode学习C++(一项目的建立)
  8. 有负数c语言除法,C语言负数的除法和求余运算
  9. IDM6.31注册机
  10. 微信最新的系统默认emoji表情集
  11. Ardunio程序设计基础 一
  12. 删除文件夹需要管理员权限的解决方法
  13. 小程序emijo表情的正则问题
  14. 几种聚类算法的对比实验
  15. html中span跟div属性,HTML 的 div 和 span 标签
  16. uniapp 微信小程序 map自定义气泡customCallout
  17. yuque-helper 1.0 发布了
  18. pytorch-retinanet训练自己的数据集
  19. linux c语言 cmos,c语言编写程序读写CMOS内容
  20. Ajax异步(7)前端

热门文章

  1. 洛谷 P1919 【模板】A*B Problem升级版(FFT快速傅里叶)
  2. 微信公众号关注/取消关注事件推送开发记录
  3. 织梦后台模块管理空白不显示的解决方法
  4. Linux基础命令(管理工具)
  5. Ureport2的表格更改小技巧
  6. OpenCV每日函数 thinning函数(细化)
  7. 联想笔记本G400使用VS2013时,笔记本快捷键与软件快捷键冲突解决方案
  8. windows安装hadoop教程,带截图
  9. 赌运挖洞之Apache目录浏览
  10. 白帽子挖洞第II篇作业--xray+fofa主动扫描