csansoon

P7.05 P87920 Equal to the sum of the rest (II)

Nov 12th, 2018
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. bool is_sum_of_the_rest (const vector <int>& v, int suma, int n);
  7.  
  8. int main(){
  9.     int n;
  10.     while (cin >> n) {
  11.         vector <int> v (n);
  12.         int suma = 0;
  13.         for (int i = 0; i < n; ++i) {
  14.             int input;
  15.             cin >> input;
  16.             v[i] = input;
  17.             suma = suma + input;
  18.         }
  19.         if (is_sum_of_the_rest(v, suma, n)) cout << "YES" << endl;
  20.         else cout << "NO" << endl;
  21.  
  22.     }
  23.  
  24. }
  25.  
  26.  
  27. bool is_sum_of_the_rest (const vector <int>& v, int suma, int n) {
  28.     for (int i = 0; i < n; ++i) {
  29.         if (suma - v[i] == v[i]) return true;
  30.     }
  31.     return false;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment