JPMorgan ChaseOA #29
Maximum Information (DA)
Estimated MediumJudge-ready
Topics (AI-labelled)DP Basics
You must choose a starting point and collect its security value, then repeatedly jump +k and collect the value where you land, stopping only when the next jump would go out of bounds. You cannot stop early or choose nothing, and values may be negative; find the total for the best starting point.
Input
The first line contains n k, followed by n security values; original bounds 1≤n≤1000000, 1≤k≤n, −1000≤security[i]≤1000.
Output
Output a single integer answer.
Example 1
Input:
5 2
2 -3 4 6 1
Output:
7
Example 2
Input:
2 1
5 -10
Output:
-5
Example 3
Input:
3 2
-5 -2 -3
Output:
-2
Example notes
The outputs of the three public examples are, in order: 7; -5; -2. These answers have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…