Investment Game (APCS 2023-10 Expert)
2.0s 256MDaily returns are \(a_1,\ldots,a_n\). Choose one contiguous investment period and ignore the returns of at most \(k\) days within it using medals. All other returns in that period count. Choosing no period earns zero. Maximize the return.
Input Format
Read \(n,k\), then all daily returns.
Output Format
Print the maximum return.
Constraints
\(1\le n\le150000\), \(0\le k\le20\); \(-10000\le a_i\le10000\).
Scoring
- 20 points: \(k=0,n\le2000\).
- 20 points: \(k=0\).
- 60 points: \(1\le k\le20\).
Each scored test is worth 5 points.
Sample Input 1
9 0
3 1 -2 3 -2 3 -5 2 2
Sample Output 1
6
Sample Input 2
9 2
3 1 -2 3 -2 3 -5 2 2
Sample Output 2
12
Sample Input 3
9 4
3 1 -2 3 -2 3 -5 2 2
Sample Output 3
14
Sample Input 4
3 0
-1 -5 -3
Sample Output 4
0
Source
APCS 2023-10 public archive version: m373。
Log in to write and submit code.
Log in