#P1725. Chasing the Frog in Gensokyo
Chasing the Frog in Gensokyo
Chasing the Frog in Gensokyo
In the mystical world of Gensokyo, Cirno the ice fairy is notorious for her foolish behavior. One day, while playing her frozen frog game, she discovered that the frog had cleverly escaped to the opposite bank of a river before she could freeze it! Determined to teach the frog a lesson, Cirno decides to chase it along the river bank.
The river is modeled as a sequence of cells numbered from \(0\) to \(N\). Cirno starts at cell \(0\) (whose freeze index is \(A_0=0\)) and can only move to cells with higher numbers. When she is at cell \(i\), she can jump to any cell in the inclusive range \([i+L,\, i+R]\). Note that if her next position exceeds \(N\), i.e. if it is greater than \(N\), it is considered that she has reached the opposite bank of the river.
Each cell \(i\) has an associated freeze index \(A_i\). When Cirno stops on a cell, she collects the freeze index of that cell. Her goal is to maximize the total freeze index accumulated by the time she reaches the other side.
The dynamic programming recurrence for this problem can be expressed as follows for any cell \(x\) (where \(x \ge L\)): $$dp[x] = A_x + \max_{\max(0, x-R) \le i \le x-L} \{ dp[i] \}$$ The final answer is the maximum \(dp[i]\) among all cells \(i\) such that \(i+R > N\), since from these cells Cirno can make a jump that takes her beyond cell \(N\).
inputFormat
The first line contains three integers \(N\), \(L\), and \(R\) separated by spaces.
The second line contains \(N\) integers. The \(i\)-th integer (for \(1 \le i \le N\)) represents the freeze index \(A_i\) of cell \(i\). Note that the freeze index of cell \(0\) is always \(0\) and is not included in the input.
outputFormat
Output a single integer, the maximum total freeze index that Cirno can accumulate by the time she reaches the opposite bank of the river.
sample
5 2 3
1 2 3 4 5
8
</p>