Split
InterviewTime limit2sMemory limit1024 MB
Given a distinct integer sequence, find its maximum, then output the sum of elements before it and the sum of elements after it.
- Level
Easy1 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
You are given an integer sequence A = (A1, A2, ..., AN) of length N. All values in A are distinct.
When the sequence is split at its maximum value, output the sum of the values before the maximum and the sum of the values after the maximum.
That is, if the maximum value of the sequence A is Ax, output A1 + A2 + … + Ax-1 and Ax+1 + Ax+2 + … + AN.
If there is no value before the maximum, the sum of the values before the maximum is 0.
Likewise, if there is no value after the maximum, the sum of the values after the maximum is 0.
Input
Input is given from standard input in the following format.
N
A1 A2 … AN
Output
The output consists of 2 lines.
On line 1, output the sum of the values before the maximum value of the integer sequence A.
On line 2, output the sum of the values after the maximum value of the integer sequence A.
Constraints
1 ≦ N ≦ 100.1 ≦ Ai ≦ 2000(1 ≦ i ≦ N).Ai ≠ Aj(1 ≦ i < j ≦ N).