LearnPy Hub
← Lists problems
Hard

Largest Sum of Neighbours

Read integers and print the largest sum of a run of one or more neighbouring numbers, then the start and end positions (from 0) of the first run with that sum. Keep a running sum and restart it when it would drop below the current number (Kadane's idea).

Input

Integers separated by spaces.

Output

Two lines.

Sample 1

Input
-2 1 -3 4 -1 2 1 -5 4
Output
6
3 6

Sample 2

Input
5
Output
5
0 0
solution.py
Output appears here
Largest Sum of Neighbours · Python practice problem · LearnPy Hub