#P6564. [POI 2007] 堆积木KLO

    ID: 7335 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2007树状数组POI(波兰)O2优化

[POI 2007] 堆积木KLO

Problem Description

PinkRabbit got a tall tower made of nn stacked blocks from his npy, and each block has a number written on it. Let the number on the ii-th block from bottom to top be aia_i. We directly denote a tower whose numbers are a1,a2,,ana_1, a_2, \dots, a_n by {a1,a2,,an}\{a_1, a_2, \dots, a_n\}. PinkRabbit defines the value of a tower {a1,a2,,am}\{a_1, a_2, \dots, a_m\} as i=1m[ai=i]\sum_{i=1}^m [a_i = i].

PinkRabbit can delete any number of blocks from the current tower. The remaining blocks will fall under gravity until they cannot fall anymore. For example, if we delete the second block from bottom to top in the tower {1,1,2,4,5}\{1,1,2,4,5\}, we get the tower {1,2,4,5}\{1,2,4,5\}, and the value of the new tower is 22.

PinkRabbit wants to delete any number of blocks from the current tower so that the value of the final tower is maximized. Since he always wins, he asks you to answer this question.

Input Format

The first line contains a positive integer nn, indicating the initial height of the tower.
The second line contains nn positive integers a1,a2,,ana_1, a_2, \dots, a_n, where aia_i is the number on the ii-th block from bottom to top in the initial state.

Output Format

Output one integer in one line, indicating the maximum value that can be obtained.

5
1 1 2 5 4
3

Hint

Explanation of Sample 1
In the initial state {1,1,2,5,4}\{1,1,2,5,4\}, only a1a_1 satisfies ai=ia_i = i, so the total value is 11.
Delete the second block from bottom to top, and we get {1,2,5,4}\{1,2,5,4\}. Then a1,a2,a4a_1, a_2, a_4 all satisfy ai=ia_i = i, so the total value is 33.
It is easy to prove that there is no better plan.

Constraints
For 100%100\% of the testdata, 1n1051 \le n \le 10^5, 1ai1061 \le a_i \le 10^6

Translated by ChatGPT 5