103490: [Atcoder]ABC349 A - Zero Sum Game

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:10 Solved:0

Description

Score: $100$ points

Problem Statement

There are $N$ people labeled $1$ to $N$, who have played several one-on-one games without draws. Initially, each person started with $0$ points. In each game, the winner's score increased by $1$ and the loser's score decreased by $1$ (scores can become negative). Determine the final score of person $N$ if the final score of person $i\ (1\leq i\leq N-1)$ is $A_i$. It can be shown that the final score of person $N$ is uniquely determined regardless of the sequence of games.

Constraints

  • $2 \leq N \leq 100$
  • $-100 \leq A_i \leq 100$
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\ldots$ $A_{N-1}$

Output

Print the answer.


Sample Input 1

4
1 -2 -1

Sample Output 1

2

Here is one possible sequence of games where the final scores of persons $1, 2, 3$ are $1, -2, -1$, respectively.

  • Initially, persons $1, 2, 3, 4$ have $0, 0, 0, 0$ points, respectively.
  • Persons $1$ and $2$ play, and person $1$ wins. The players now have $1, -1, 0, 0$ point(s).
  • Persons $1$ and $4$ play, and person $4$ wins. The players now have $0, -1, 0, 1$ point(s).
  • Persons $1$ and $2$ play, and person $1$ wins. The players now have $1, -2, 0, 1$ point(s).
  • Persons $2$ and $3$ play, and person $2$ wins. The players now have $1, -1, -1, 1$ point(s).
  • Persons $2$ and $4$ play, and person $4$ wins. The players now have $1, -2, -1, 2$ point(s).

In this case, the final score of person $4$ is $2$. Other possible sequences of games exist, but the score of person $4$ will always be $2$ regardless of the progression.


Sample Input 2

3
0 0

Sample Output 2

0

Sample Input 3

6
10 20 30 40 50

Sample Output 3

-150

Input

Output

分数:100分

问题描述

有N个人,编号为1到N,他们进行了一些一对一的比赛,没有平局。最初,每个人得分都是0。在每场比赛中,胜者得分加1,败者得分减1(分数可以为负)。如果第i个人(1≤i≤N-1)的最终得分为$A_i$,请确定第N个人的最终得分。可以证明,无论比赛顺序如何,第N个人的最终得分是唯一确定的。

限制条件

  • 2 ≤ N ≤ 100
  • -100 ≤ $A_i$ ≤ 100
  • 所有输入值都是整数。

输入

输入从标准输入以以下格式给出:

$N$
$A_1$ $A_2$ $\ldots$ $A_{N-1}$

输出

打印答案。


样例输入1

4
1 -2 -1

样例输出1

2

以下是一个可能的比赛序列,使得第1, 2, 3个人的最终分数分别为1, -2, -1:

  • 最初,第1, 2, 3, 4个人分别有0, 0, 0, 0分。
  • 第1和2个人比赛,第1个人赢。现在他们的分数是1, -1, 0, 0。
  • 第1和4个人比赛,第4个人赢。现在他们的分数是0, -1, 0, 1。
  • 第1和2个人比赛,第1个人赢。现在他们的分数是1, -2, 0, 1。
  • 第2和3个人比赛,第2个人赢。现在他们的分数是1, -1, -1, 1。
  • 第2和4个人比赛,第4个人赢。现在他们的分数是1, -2, -1, 2。

在这种情况下,第4个人的最终分数是2。还有其他可能的比赛序列,但无论比赛顺序如何,第4个人的分数总是2。


样例输入2

3
0 0

样例输出2

0

样例输入3

6
10 20 30 40 50

样例输出3

-150

加入题单

算法标签: