mitakvd

04. Equal Pairs

Jul 8th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main () {
  8.  
  9.     int number;
  10.     cin >> number;
  11.  
  12.     int sum = 0;
  13.     int currentSum = 0;
  14.     int diff = 0;
  15.     int maxDiff = 0;
  16.  
  17.     for(int i = 1; i <= number; i++) {
  18.         int num1, num2;
  19.         cin >> num1 >> num2;
  20.  
  21.         if (i == 1) {
  22.             sum = num1 + num2;
  23.         }
  24.  
  25.         if (i > 1) {
  26.             currentSum = num1 + num2;
  27.  
  28.             if (currentSum != sum) {
  29.                 diff = currentSum - sum;
  30.                 currentSum = sum;
  31.             }
  32.  
  33.             if (diff > maxDiff) {
  34.                 maxDiff = diff;
  35.             }
  36.             currentSum = 0;
  37.             diff = 0;
  38.         }
  39.     }
  40.  
  41.  
  42.     if (maxDiff != 0) {
  43.         cout << "No, maxdiff=" << maxDiff << endl;
  44.     } else {
  45.         cout << "Yes, value=" << sum << endl;
  46.     }
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment