SHARE
TWEET

04.Equal Pairs

a guest Jul 12th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8.     int n;
  9.     cin >> n;
  10.  
  11.     int maxDiff = 0;
  12.     int sum = 0;
  13.     int prevSum = 0;
  14.  
  15.     for(int i = 0; i < n; i++){
  16.         int number1, number2;
  17.         cin >> number1 >> number2;
  18.  
  19.         sum = number1 + number2;
  20.  
  21.         if(i  == 0){
  22.             prevSum = sum;
  23.         }
  24.         else if(sum != prevSum){
  25.             int difference = abs(sum - prevSum);
  26.  
  27.             if(difference > maxDiff){
  28.                 maxDiff = difference;
  29.             }
  30.         }
  31.  
  32.         prevSum = sum;
  33.     }
  34.  
  35.     if(maxDiff == 0){
  36.         cout << "Yes, value=" << sum << endl;
  37.     } else {
  38.         cout << "No, maxdiff=" << maxDiff << endl;
  39.     }
  40.  
  41. return 0;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top