JPMorgan ChaseOA #29
Maximum Information (DA)
估计中等可在线判题
考点(AI 标注)动规入门
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.
输入格式
The first line contains n k, followed by n security values; original bounds 1≤n≤1000000, 1≤k≤n, −1000≤security[i]≤1000.
输出格式
Output a single integer answer.
样例 1
输入:
5 2
2 -3 4 6 1
输出:
7
样例 2
输入:
2 1
5 -10
输出:
-5
样例 3
输入:
3 2
-5 -2 -3
输出:
-2
样例说明
The outputs of the three public examples are, in order: 7; -5; -2. These answers have been checked by independent enumeration or direct simulation.