CF1472C.Long Jumps

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp found under the Christmas tree an array aa of nn elements and instructions for playing with it:

  • At first, choose index ii (1≤i≤n1 \leq i \leq n) — starting position in the array. Put the chip at the index ii (on the value aia_i).
  • While i≤ni \leq n, add aia_i to your score and move the chip aia_i positions to the right (i.e. replace ii with i+aii + a_i).
  • If i>ni \gt n, then Polycarp ends the game.

For example, if n=5n = 5 and a=[7,3,1,2,3]a = [7, 3, 1, 2, 3], then the following game options are possible:

  • Polycarp chooses i=1i = 1. Game process: i=1⟶+78i = 1 \overset{+7}{\longrightarrow} 8. The score of the game is: a1=7a_1 = 7.
  • Polycarp chooses i=2i = 2. Game process: i=2⟶+35⟶+38i = 2 \overset{+3}{\longrightarrow} 5 \overset{+3}{\longrightarrow} 8. The score of the game is: a2+a5=6a_2 + a_5 = 6.
  • Polycarp chooses i=3i = 3. Game process: i=3⟶+14⟶+26i = 3 \overset{+1}{\longrightarrow} 4 \overset{+2}{\longrightarrow} 6. The score of the game is: a3+a4=3a_3 + a_4 = 3.
  • Polycarp chooses i=4i = 4. Game process: i=4⟶+26i = 4 \overset{+2}{\longrightarrow} 6. The score of the game is: a4=2a_4 = 2.
  • Polycarp chooses i=5i = 5. Game process: i=5⟶+38i = 5 \overset{+3}{\longrightarrow} 8. The score of the game is: a5=3a_5 = 3.

Help Polycarp to find out the maximum score he can get if he chooses the starting index in an optimal way.

波利卡普在圣诞树下发现了一个包含 nn 个元素的数组 aa,以及一份关于如何与该数组互动的游戏说明:

  • 首先,选择一个下标 ii(1≤i≤n1 \leq i \leq n)——作为数组中的起始位置。将棋子放置在下标 ii 处(即数值 aia_i 上)。
  • 当 i≤ni \leq n 时,将 aia_i 加入你的得分,并将棋子向右移动 aia_i 个位置(即令 ii 更新为 i+aii + a_i)。
  • 若 i>ni > n,则波利卡普结束游戏。

例如,若 n=5n = 5 且 a=[7,3,1,2,3]a = [7, 3, 1, 2, 3],则可能的游戏过程如下:

  • 波利卡普选择 i=1i = 1。游戏过程:i=1⟶+78i = 1 \overset{+7}{\longrightarrow} 8。游戏得分为:a1=7a_1 = 7。
  • 波利卡普选择 i=2i = 2。游戏过程:i=2⟶+35⟶+38i = 2 \overset{+3}{\longrightarrow} 5 \overset{+3}{\longrightarrow} 8。游戏得分为:a2+a5=6a_2 + a_5 = 6。
  • 波利卡普选择 i=3i = 3。游戏过程:i=3⟶+14⟶+26i = 3 \overset{+1}{\longrightarrow} 4 \overset{+2}{\longrightarrow} 6。游戏得分为:a3+a4=3a_3 + a_4 = 3。
  • 波利卡普选择 i=4i = 4。游戏过程:i=4⟶+26i = 4 \overset{+2}{\longrightarrow} 6。游戏得分为:a4=2a_4 = 2。
  • 波利卡普选择 i=5i = 5。游戏过程:i=5⟶+38i = 5 \overset{+3}{\longrightarrow} 8。游戏得分为:a5=3a_5 = 3。

请帮助波利卡普找出:若他以最优方式选择起始下标,所能获得的最大得分是多少。

输入格式

The first line contains one integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. Then tt test cases follow.

The first line of each test case contains one integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the length of the array aa.

The next line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) — elements of the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 数组 aa 的长度。

下一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 数组 aa 的元素。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output on a separate line one number — the maximum score that Polycarp can get by playing the game on the corresponding array according to the instruction from the statement. Note that Polycarp chooses any starting position from 11 to nn in such a way as to maximize his result.

对于每个测试用例,在单独一行输出一个数字——即 Polycarp 按照题目描述中的规则在对应数组上进行游戏所能获得的最大得分。注意:Polycarp 可以任意选择起始位置(从 11 到 nn),以使他的得分最大化。

输入输出样例

  • 输入#1

    4
    5
    7 3 1 2 3
    3
    2 1 4
    6
    2 1000 2 3 995 1
    5
    1 1 1 1 1

    输出#1

    7
    6
    1000
    5

说明/提示

The first test case is explained in the statement.

In the second test case, the maximum score can be achieved by choosing i=1i = 1.

In the third test case, the maximum score can be achieved by choosing i=2i = 2.

In the fourth test case, the maximum score can be achieved by choosing i=1i = 1.

第一个测试用例已在题目描述中说明。

在第二个测试用例中,选择 i=1i = 1 可以获得最高得分。

在第三个测试用例中,选择 i=2i = 2 可以获得最高得分。

在第四个测试用例中,选择 i=1i = 1 可以获得最高得分。

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

首页