#C13032. First Occurrence Maximum Subarray Index

    ID: 42526 Type: Default 1000ms 256MiB

First Occurrence Maximum Subarray Index

First Occurrence Maximum Subarray Index

You are given an array of integers. Your task is to find the starting index of the first occurrence of a contiguous subarray that has the maximum sum among all possible contiguous subarrays. If the array is empty, output -1.

The contiguous subarray is defined as a sequence of consecutive elements from the original array. Formally, if the array is denoted as \(a_0, a_1, \dots, a_{n-1}\), you need to find an index \(i\) and a length \(l\) (with \(1 \leq l \leq n\)) such that the sum \(S = \sum_{j=i}^{i+l-1} a_j\) is maximized. If there are multiple such subarrays, choose the one with the smallest starting index \(i\).

Note: In case the input array is empty, the result should be \(-1\).

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  1. The first line contains an integer \(n\) (which can be 0), representing the number of elements in the array.
  2. If \(n > 0\), the second line contains \(n\) space-separated integers denoting the elements of the array.

outputFormat

Output a single integer through standard output (stdout), which is the starting index of the contiguous subarray that has the maximum sum. If the array is empty, output \(-1\).

## sample
1
1
0

</p>