#C12277. Maximum Subarray Indices
Maximum Subarray Indices
Maximum Subarray Indices
Given an array of integers, your task is to identify the contiguous subarray that has the maximum sum. If there exist multiple subarrays with the same maximum sum, choose the one that appears first. In case the array is empty, the output should be (-1, -1)
.
The maximum subarray sum is defined as: $$\max_{0 \leq i \leq j < n}\sum_{k=i}^{j}a_k$$.
You are expected to read from standard input (stdin) and write your result to standard output (stdout). The output should be two integers: the starting and ending indices of the subarray with the maximum sum.
inputFormat
The input begins with an integer n
on the first line, representing the number of elements in the array. If n > 0
, the second line contains n
space-separated integers representing the array. If n = 0
, no further input is provided.
outputFormat
Output two integers separated by a space, which are the starting and ending indices (0-indexed) of the contiguous subarray that has the maximum sum. If the array is empty, output "-1 -1".
## sample1
1
0 0