CF1491C.Pekora and Trampoline

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a trampoline park with nn trampolines in a line. The ii-th of which has strength SiS_i.

Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice.

If at the moment Pekora jumps on trampoline ii, the trampoline will launch her to position i+Sii + S_i, and SiS_i will become equal to max⁡(Si−1,1)\max(S_i-1,1). In other words, SiS_i will decrease by 11, except of the case Si=1S_i=1, when SiS_i will remain equal to 11.

If there is no trampoline in position i+Sii + S_i, then this pass is over. Otherwise, Pekora will continue the pass by jumping from the trampoline at position i+Sii + S_i by the same rule as above.

Pekora can't stop jumping during the pass until she lands at the position larger than nn (in which there is no trampoline). Poor Pekora!

Pekora is a naughty rabbit and wants to ruin the trampoline park by reducing all SiS_i to 11. What is the minimum number of passes she needs to reduce all SiS_i to 11?

有一个由 nn 个蹦床排成一列组成的蹦床公园,其中第 ii 个蹦床的弹力为 SiS_i。

Pekora 可以进行多次“跳跃轮次”(passes)来跳跃这些蹦床。每次轮次开始时,她可任选一个蹦床作为起跳点。

当 Pekora 跳到第 ii 个蹦床时,该蹦床会将她弹射至位置 i+Sii + S_i,同时 SiS_i 的值变为 max⁡(Si−1,1)\max(S_i-1,1)。换言之,SiS_i 将减小 11;但若原本 Si=1S_i = 1,则 SiS_i 保持为 11。

若位置 i+Sii + S_i 处没有蹦床(即超出范围),则本轮次结束。否则,Pekora 将从位置 i+Sii + S_i 处的蹦床上继续按上述规则跳跃。

在一轮次中,Pekora 无法中途停止跳跃,直到她落点位置大于 nn(即落在不存在蹦床的位置)为止。可怜的 Pekora!

Pekora 是一只淘气的兔子,她想通过将所有 SiS_i 全部减少至 11 来毁掉这个蹦床公园。请问:她最少需要多少轮次才能使所有 SiS_i 均变为 11?

输入格式

The first line contains a single integer tt (1≤t≤5001 \le t \le 500) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤50001 \leq n \leq 5000) — the number of trampolines.

The second line of each test case contains nn integers S1,S2,…,SnS_1, S_2, \dots, S_n (1≤Si≤1091 \le S_i \le 10^9), where SiS_i is the strength of the ii-th trampoline.

It's guaranteed that the sum of nn over all test cases doesn't exceed 50005000.

第一行包含一个整数 tt(1≤t≤5001 \le t \le 500)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤50001 \leq n \leq 5000)—— 蹦床的数量。

每个测试用例的第二行包含 nn 个整数 S1,S2,…,SnS_1, S_2, \dots, S_n(1≤Si≤1091 \le S_i \le 10^9),其中 SiS_i 表示第 ii 个蹦床的强度。

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

输出格式

For each test case, output a single integer — the minimum number of passes Pekora needs to do to reduce all SiS_i to 11.

对于每个测试用例,输出一个整数——Pekora 所需的最少通关次数,使得所有 SiS_i 均变为 11。

输入输出样例

  • 输入#1

    3
    7
    1 4 2 2 2 2 2
    2
    2 3
    5
    1 1 1 1 1

    输出#1

    4
    3
    0

说明/提示

For the first test case, here is an optimal series of passes Pekora can take. (The bolded numbers are the positions that Pekora jumps into during these passes.)

  • [1,4,2,2,2,2,2][1,4,\textbf{2},2,\textbf{2},2,\textbf{2}]
  • [1,4,1,2,1,2,1][1,\textbf{4},1,2,1,\textbf{2},1]
  • [1,3,1,2,1,1,1][1,\textbf{3},1,2,\textbf{1},\textbf{1},\textbf{1}]
  • [1,2,1,2,1,1,1][1,\textbf{2},1,\textbf{2},1,\textbf{1},\textbf{1}]

For the second test case, the optimal series of passes is show below.

  • [2,3][\textbf{2},3]
  • [1,3][1,\textbf{3}]
  • [1,2][1,\textbf{2}]

For the third test case, all SiS_i are already equal to 11.

对于第一个测试用例,以下是Pekora可以采取的最优传球序列。(加粗的数字表示Pekora在这些传球过程中跳入的位置。)

  • [1,4,2,2,2,2,2][1,4,\textbf{2},2,\textbf{2},2,\textbf{2}]
  • [1,4,1,2,1,2,1][1,\textbf{4},1,2,1,\textbf{2},1]
  • [1,3,1,2,1,1,1][1,\textbf{3},1,2,\textbf{1},\textbf{1},\textbf{1}]
  • [1,2,1,2,1,1,1][1,\textbf{2},1,\textbf{2},1,\textbf{1},\textbf{1}]

对于第二个测试用例,最优传球序列如下所示。

  • [2,3][\textbf{2},3]
  • [1,3][1,\textbf{3}]
  • [1,2][1,\textbf{2}]

对于第三个测试用例,所有 SiS_i 已经等于 11。

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

首页