csansoon

P6.16 P81585 Equal to the sum of the rest (I)

Nov 7th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main () {
  5.         int n;
  6.         while (cin >> n) {
  7.                 int max = 0;
  8.                 int suma = 0;
  9.                 for (int i = 0; i < n; ++i) {
  10.                         int x;
  11.                         cin >> x;
  12.                         suma += x;
  13.                         if (x > max) max = x;
  14.                 }
  15.                 if (suma - max == max) cout << "YES" << endl;
  16.                 else cout << "NO" << endl;
  17.         }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment