Shifting Stacks (递增思想特例化)

简介: Shifting Stacks (递增思想特例化)

time limit per test1 second

memory limit per test256 megabytes


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


题目分析我们可以知道0,1,2.……n是最小的递增整数,所以我们可以判断用数列的和比较。


具体操作看代码。


听懂了记得给个赞鼓励一下,码字不易,用爱发电。


上ac代码。


f58230e9f063709cf3167704f4efdf14.gif

有事你就q我;QQ2917366383


学习算法

 

  #include<iostream>
  using namespace std;
  int n,b;
  int main()
  {
    int a[150000];
    int t;
    cin>>t;
    while(t--)
    {
        long long sum1,sum2;
      b=sum1=sum2=0;
      cin>>n;
      for(int i=1;i<=n;i++) 
      cin>>a[i];
      for(int i=1;i<=n;i++)
      {
        sum1+=a[i];
        sum2+=(i-1);//0,到i-1的和 
        if(sum1<sum2)
        {
        cout<<"NO"<<endl;
          b=1;
          break;
        }
      }
      if(!b)
      cout<<"YES"<<endl;
    }
  }


相关文章
|
6月前
|
人工智能 Java 数据库连接
Spring事务失效场景
本文深入探讨了Spring框架中事务管理可能失效的几种常见场景及解决方案,包括事务方法访问级别不当、方法内部自调用、错误的异常处理、事务管理器或数据源配置错误、数据库不支持事务以及不合理的事务传播行为或隔离级别。通过合理配置和正确使用`@Transactional`注解,开发者可以有效避免这些问题,确保应用的数据一致性和完整性。
350 10
|
安全 Unix Linux
Windows如何远程连接服务器?服务器远程连接图文教程
服务器操作系统可以实现对计算机硬件与软件的直接控制和管理协调,任何计算机的运行离不开操作系统,服务器也一样,服务器操作系统主要分为四大流派:Windows Server、Netware、Unix和Linux。今天驰网飞飞将和你分享Windows server远程连接图文教程,希望可以帮助到你
5303 4
Windows如何远程连接服务器?服务器远程连接图文教程
|
12月前
|
Java 测试技术 数据库连接
使用Spring Boot编写测试用例:实践与最佳实践
使用Spring Boot编写测试用例:实践与最佳实践
1120 0
|
安全 IDE 开发工具
Python——记录pip问题(解决下载慢、升级失败问题)
Python——记录pip问题(解决下载慢、升级失败问题)
802 1
|
NoSQL Redis Docker
Docker获取镜像和运行镜像
这篇文章介绍了如何使用Docker获取镜像以及运行镜像的具体步骤和命令。
1791 0
|
文件存储
一篇文章讲明白LTE中的各种ID含义
一篇文章讲明白LTE中的各种ID含义
726 0
|
BI 数据处理 Apache
[AIGC] 深入理解Flink中的窗口、水位线和定时器
[AIGC] 深入理解Flink中的窗口、水位线和定时器
303 2
|
存储
数据结构——双向链表(C语言版)
数据结构——双向链表(C语言版)
97 2
【JAVA学习之路 | 提高篇】锁(Lock)
【JAVA学习之路 | 提高篇】锁(Lock)