LogiQuest

63. Best Subarray with Bounds

MediumKadane

Print the maximum subarray sum and the 1-based start and end of the shortest earliest subarray achieving it: among subarrays with the maximum sum choose the one with the smallest start, and among those the smallest end.

Input format

Line 1: n Line 2: n integers

Output format

sum start end

Example 1

Input

5
-2 3 -1 4 -5

Output

6 2 4

Example 2

Input

3
-3 -1 -2

Output

-1 2 2

Constraints

1 ≤ n ≤ 2000

Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.

Loading the MyLoginn IDE…