P26527 [AtCoder] Split
提高-
题目描述

Problem Description

Given an integer sequence \( A = (A_1, A_2, \ldots, A_N) \) of length \( N \). All values in the sequence \( A \) are distinct.

When the sequence is split at the maximum value, output the sum of the values before the maximum value and the sum of the values after the maximum value.

That is, if the maximum value of the sequence \( A \) is \( A_x \), output \( A_1 + A_2 + \cdots + A_{x-1} \) and \( A_{x+1} + A_{x+2} + \cdots + A_N \).

If there are no values before the maximum value, the sum of the values before the maximum value is \( 0 \).

Similarly, if there are no values after the maximum value, the sum of the values after the maximum value is \( 0 \).

Input Format

The input is given from the standard input in the following format:

\( N \) \( A_1 \) \( A_2 \) \( \cdots \) \( A_N \)

Output Format

The output consists of 2 lines.

On the first line, output the sum of the values in the integer sequence \( A \) that are before the maximum value.

On the second line, output the sum of the values in the integer sequence \( A \) that are after the maximum value.

Sample Input and Output

Sample Input #1

5
9 3 16 8 1

Sample Output #1

12
9

Sample Input #2

6
121 8 5 4 1 3

Sample Output #2

0
21

Sample Input #3

1
2000

Sample Output #3

0
0

Sample Input #4

10
9 12 30 63 55 8 10 1 27 13

Sample Output #4

51
114

Notes/Hints

Constraints

  • \( 1 \leq N \leq 100 \).
  • \( 1 \leq A_i \leq 2000 \) (\( 1 \leq i \leq N \)).
  • \( A_i \neq A_j \) (\( 1 \leq i < j \leq N \)).

Sample Explanation 1

The maximum value of this sequence is \( 16 \). Therefore, output the sum of \( 9, 3 \) which is \( 12 \), and the sum of \( 8, 1 \) which is \( 9 \), separated by a newline.

Sample Explanation 2

The maximum value of this sequence is \( 121 \). Since there are no values before \( 121 \), output \( 0 \) first. Then output the sum of \( 8, 5, 4, 1, 3 \) which is \( 21 \).

Sample Explanation 3

There might be no values before or after the maximum value.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 9 3 16 8 1
样例输出
12 9