Loading...
Loading...
Loading...
You have the daily profit of n days. Choose k consecutive days so that their total profit is as large as possible, and print that total. Profits can be negative.
Example
Input
6 3 2 1 5 1 3 2
Output
9
The windows total 8, 7, 9 and 6. The best is 9.
Try the problem first. Open one hint at a time.
Adding k values for every window costs about n x k steps, which is too slow.
Move the window by one day: add the new day and subtract the day that left.
Start the best total from the first window, not from 0, because all totals can be negative.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor