시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 142 | 77 | 72 | 54.962% |
A subsegment is a continuous piece of the list. For example: In the list [1, 2, 3, 4, 5], we have subsegments such as [1, 2, 3, 4], [2, 3] or [3, 4]. [1, 3, 4, 5] is not a subsegment because 1 and 3 are not continuous in the original list.
Given the list [3, 1, 2, 4, 2, 2, 3, 6] the non-decreasing subsegments are:
Hence the longest subsegment is [2, 2, 3, 6] and has a size of 4 elements.
You’ll need to compute the length of the longest subsegment and the sum of these elements. In a case of more than one non-decreasing subsegment with the maximum length, return the length and the sum of the one who appears first in the input.
The first line will contain an integer n (1 ≤ n ≤ 105), the size of the list. The next line will contain n integers, the elements of the list, separated by spaces (the values will be between 1 and 109).
Two integers separated by a single space: the first one representing the size of the longest non-decreasing subsegment of the list and the second it’s sum. In the case of equally longest non-decreasing subsegment, output the length and the sum of the subsegment that appears first.
5 1 2 3 4 5
5 15
9 514 630 327 242 504 763 353 699 486
3 1509
7 449 434 996 140 918 205 948
2 1430
5 721 231 521 613 792
4 2157