Checkpoint: The Widest Window
Challenge on lesson: Checkpoint — Fuse the Window
CHALLENGE
Difficulty: advanced+25 XP
**Task.** Stand on cell 1 of a strip of n cells; cell i has value g_i (may be negative). Repeatedly jump forward at most k cells (from i to i+1..i+k); each landing cell adds its value. Maximize the total collected when you reach cell n (you must end exactly there). Print the maximum. **Constraints:** 2 ≤ n ≤ 200000; 1 ≤ k ≤ min(2000, n−1); −50000 ≤ g_i ≤ 50000. Totals reach ~10^10 — 64-bit. **Budget check:** the dp[i] = g_i + max(dp[i−k..i−1]) recurrence is O(n·k) = 4·10^8 naive — risky; the fused window-min is O(n).
Press Submit to check your solution.
Back to lesson: Checkpoint — Fuse the Window