码迷,mamicode.com
首页 > 其他好文 > 详细

2021.2.19cf痛苦经历

时间:2021-02-20 11:52:20      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:move   lin   efi   class   may   header   rev   shift   any   

A. Shifting Stacks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 (1t104) — the number of test cases.

The first line of each test case contains a single integer n (1n100). The second line of each test case contains n integers hi (0hi109) — 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
Copy
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
output
Copy
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.

 

 错题记录:

  1. #include<bits/stdc++.h>
  2. #include<algorithm>
  3. #define ll long long
  4. using namespace std;
  5. const ll nl=2e5+5;
  6. ll a[nl]={0};
  7. ll b[nl]={0};
  8. int main(){
  9. ll t;
  10. cin>>t;
  11. while(t--){
  12. ll n;
  13. cin>>n;
  14. ll i;
  15. ll sum=0,num=0;
  16. ll flag=0;
  17. for(i=0;i<n;i++){
  18. cin>>a[i];
  19. sum+=a[i];
  20. num+=i;
  21. if(sum<num){
  22. cout<<"NO"<<endl;
  23. flag=1;
  24. break;
  25. }
  26. }
  27. for(i=0;i<n;i++){
  28. a[i]=0;
  29. }
  30. if(flag==0){
  31. cout<<"YES"<<endl;
  32. }
  33. }
  34. }21-24行break后会直接跳出程序,不会继续输入*************

2021.2.19cf痛苦经历

标签:move   lin   efi   class   may   header   rev   shift   any   

原文地址:https://www.cnblogs.com/yyscn/p/14414167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!