#C14312. Longest Zero Sum Subarray
Longest Zero Sum Subarray
Longest Zero Sum Subarray
Given an array of integers, find the longest contiguous subarray whose sum is zero. If such a subarray exists, output the starting and ending indices (0-indexed) of the subarray. Otherwise, output -1.
Formally, you need to find indices \(i\) and \(j\) (with \(0 \le i \le j < n\)) such that \[ \sum_{k=i}^{j} a_k = 0 \] and the length \(j - i + 1\) is maximized. In case of multiple answers, output the one with the smallest starting index.
inputFormat
The input is given via standard input and consists of two lines. The first line contains an integer \(n\) (\(n \ge 0\)) representing the number of elements in the array. If \(n > 0\), the second line contains \(n\) space-separated integers.
outputFormat
Print the starting and ending indices of the longest zero-sum subarray separated by a space. If no such subarray exists, print -1.
## sample5
1 2 -2 4 -4
1 4