#P9367. [ICPC2022 Xi'an R] Strange Sum

[ICPC2022 Xi'an R] Strange Sum

题目描述

Given a sequence a1,a2,,ana_1, a_2, \ldots, a_n.

You are going to select zero or more elements of aa so that: if you select aia_i, then in any interval of length ii (formally, in a[j,j+i1]a[j, j + i - 1] for any 1jni+11 \le j \le n - i + 1) you can select at most 22 elements.

Calculate the maximal sum of the elements you select.

输入格式

The first line contains an integer nn (2n1052 \leq n \leq 10^5).

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (109ai109-10^9 \leq a_i \leq 10^9).

输出格式

Output a single integer denoting the answer.

4
1 4 3 2

7

3
-10 -10 -10

0

提示

Source: The 2022 ICPC Asia Xi'an Regional Contest Problem J.

Author: JohnVictor.