Official
A - Zero Sum Game Editorial by en_translator
For beginners
- If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
- Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
- 「Python入門 AtCoder Programming Guide for beginners (APG4bPython)」 is a Python tutorial for competitive programmers. Again, this is only in Japanese.
The sum of the \(N\) people’s score is always \(0\). Denoting by \(A_N\) the score of person \(N\), we have \(A_1+A_2+\ldots+A_{N-1}+A_N=0\), so \(A_N=-(A_1+A_2+\ldots+A_{N-1})\).
It is sufficient to receive the scores of the \((N-1)\) people, find the sum, multiply it by \(-1\), and print the result.
Sample code (C++)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin >> N;
vector<int> A(N - 1);
int sum = 0;
for (int i = 0; i < N - 1; i++)
{
cin >> A[i];
sum += A[i];
}
cout << -sum << endl;
}
Sample code (Python)
N = int(input())
A = list(map(int, input().split()))
print(-sum(A))
posted:
last update: