Loading...
Loading...
Loading...
Extend the profit problem: print the largest total of a run of consecutive days, and the first and last day of that run (days are numbered from 1). If several runs give the same total, choose the one that starts first, and among those the one that ends first.
Example
Input
6 3 -5 4 -1 3 -2
Output
6 3 5
Days 3 to 5 give 6.
Try the problem first. Open one hint at a time.
Remember the day on which the current run started.
Restart the run only when its sum is below zero, and replace the best only when current is strictly larger.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor