Advertisement
Spocoman

02. Half Sum Element

Sep 7th, 2023
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int num;
  7.     cin >> num;
  8.  
  9.     int  sum = 0;
  10.     int  maxNum = 0;
  11.  
  12.     int number;
  13.  
  14.     for (int i = 0; i < num; i++) {
  15.         cin >> number;
  16.         sum += number;
  17.  
  18.         if (number > maxNum) {
  19.             maxNum = number;
  20.         }
  21.     }
  22.  
  23.     int result = sum - maxNum;
  24.     if (maxNum == result) {
  25.         cout << "Yes\n" << "Sum = " << maxNum << endl;
  26.     }
  27.     else {
  28.         cout << "No\n" << "Diff = " << abs(maxNum - result) << endl;
  29.     }
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement