No.1389 Clumsy Calculation
タグ : / 解いたユーザー数 271
作問者 :
Kiri8128
Problem Statement
chinerist has $N$ integers $A_i\ (1\le i \le N)$. The sum of these integers is $X$.
For each $i=1,2,\dots,N$, chinerist computed "the sum of all $A_k\ (1\le k \le N)$ except $A_i$", and the result was $S_i$.
However, being careless, chinerist made a mistake in exactly $1$ of these calculations, and its result became $2$ times the correct answer.
Tell chinerist the correct answer to the calculation that was done wrong.
Input
$N\ X$ $S_1\ S_2\ \dots\ S_N$
- $2\le N \le 2\times 10^{5}$
- $0\le X \le 10^{9}$
- $1\le S_i \le 10^{9}\ (1\le i \le N)$
- All values in the input are integers.
- It is guaranteed that only $1$ of the $N$ calculation results $S_i\ (1\le i\le N)$ is wrong and that the other calculation results are correct.
Output
Output the correct result of the calculation that chinerist got wrong.
That is, output "the sum of all $A_i$ except $A_k$" for the $k$ such that "the sum of all $A_i$ except $A_k$" is not $S_k$.
The possible $k$ above may not be uniquely determined from the input, but it can be proved that the value to output is always uniquely determined (see Sample 3 for details).
Print a newline at the end.
Sample
Sample 1
Input
5 15 28 13 12 11 10
Output
14
The $5$ integers chinerist has are $1,2,3,4,5$ in this order. Here, the $1$-st calculation result should correctly be $14$ but is $28$, so output this value.
Sample 2
Input
3 17 22 10 7
Output
5
The integers chinerist has are $-5,12,10$. As shown here, chinerist may have negative integers.
Sample 3
Input
4 8 8 8 2 10
Output
4
For the integers chinerist has and the index of the wrong calculation, there are
- The integers are $4,\ 0,\ 6,\ -2$ in this order, and the $1$-st calculation is wrong
- The integers are $0,\ 4,\ 6,\ -2$ in this order, and the $2$-nd calculation is wrong
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。