CF1486A.Shifting Stacks

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

Note that the number of stacks always remains nn: stacks don't disappear when they have 00 blocks.

你有 nn 堆方块。第 ii 堆包含 hih_i 个方块,其高度即为其中的方块数量。在一次操作中,你可以从第 ii 堆(要求该堆至少有一个方块)取一个方块,并将其放到第 i+1i + 1 堆。你能否通过若干次操作使得各堆高度构成一个严格递增的序列?

注意:堆的数量始终保持为 nn:即使某堆方块数为 00,该堆也不会消失。

输入格式

First line contains a single integer tt (1≤t≤104)(1 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤100)(1 \leq n \leq 100). The second line of each test case contains nn integers hih_i (0≤hi≤109)(0 \leq h_i \leq 10^9) — starting heights of the stacks.

It's guaranteed that the sum of all nn does not exceed 10410^4.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)。每个测试用例的第二行包含 nn 个整数 hih_i(0≤hi≤1090 \leq h_i \leq 10^9)—— 各堆栈的初始高度。

保证所有测试用例中 nn 的总和不超过 10410^4。

输出格式

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).

对于每个测试用例,如果可以使高度序列严格递增,则输出 YES;否则输出 NO。

您可以以任意大小写形式输出每个字母(例如,YES、Yes、yes、yEs 均会被识别为肯定回答)。

输入输出样例

  • 输入#1

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

    输出#1

    YES
    YES
    YES
    NO
    NO
    YES

说明/提示

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 00 11.

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 33 44 55.

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 00 00 11. Both 00 11 00 and 00 00 11 are not increasing sequences, so the answer is NO.

在第一个测试用例中,无需进行任何操作,高度序列本身已经是严格递增的。

在第二个测试用例中,我们需要将第一堆的一个方块移动到第二堆,此时高度变为 00 11。

在第三个测试用例中,我们可以先将第一堆的一个方块移动到第二堆,再将第二堆的一个方块移动到第三堆,从而使高度变为 33 44 55。

在第四个测试用例中,我们无法进行任何移动,但当前序列并非递增序列,因此答案为 NO。

在第五个测试用例中,我们只能进行一次移动(从第二堆移动到第三堆),此时高度变为 00 00 11。而 00 11 00 和 00 00 11 均不是递增序列,因此答案为 NO。

输入解题思路,AI测评打分。不知道怎么写?

首页