#C2290. Longest Non-Losing Sequence
Longest Non-Losing Sequence
Longest Non-Losing Sequence
You are given the number of matches played by a team and a list of integers representing the score margin of each match. A match is considered a non-losing match if the score margin is non-negative (i.e. \(margin \ge 0\)). Your task is to determine the longest contiguous sequence of non-losing matches and output its starting and ending indices (1-indexed).
In case there is no non-losing match, or if the input list is empty, output 1 1
. If there are multiple sequences of the same maximum length, choose the one that appears first.
For example, given the margins: [1, -2, 0, 2, 3, -1, 2, 0], the longest contiguous non-losing sequence is [0, 2, 3] (using 0-based indexing: indices 2 to 4), so the output should be 3 5
when converted to 1-indexed form.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer \(N\) indicating the number of matches.
- The second line contains \(N\) space-separated integers representing the score margins of the matches.
If \(N = 0\), there will be no second line.
outputFormat
Print two space-separated integers which are the starting and ending indices (1-indexed) of the longest contiguous sequence of non-losing matches.
## sample8
1 -2 0 2 3 -1 2 0
3 5