Official

A - Zero Sum Game Editorial by en_translator


For beginners

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: