#C13157. Maximum Subarray Indices

    ID: 42664 Type: Default 1000ms 256MiB

Maximum Subarray Indices

Maximum Subarray Indices

Given an array of integers, your task is to find the contiguous subarray that has the maximum sum. More formally, find indices \(l\) and \(r\) (0-indexed) such that the subarray sum \(S = \sum_{i=l}^{r} a_i\) is maximized.

If the input array is empty, output None. In the case where all the numbers in the array are negative, consider the maximum subarray to be the first element (i.e. indices 0, 0).

Your solution should read input from standard input (stdin) and write the answer to standard output (stdout).

inputFormat

The input consists of two lines:

  • The first line contains a single integer \(n\) (\(0 \le n \le 10^5\)) representing the number of elements in the array.
  • If \(n > 0\), the second line contains \(n\) space-separated integers representing the array elements.

outputFormat

If the array is not empty, output two space-separated integers representing the starting and ending indices of the subarray with the maximum sum. If the array is empty, output None.

## sample
5
1 2 3 4 5
0 4