Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int N, sum = 0, minr = 10001;
  9.     int x, y;
  10.     cin >> N;
  11.     for (int i = 0; i < N; i++) {
  12.         cin >> x >> y;
  13.         if (x > y) {
  14.             sum += x;
  15.         } else {
  16.             sum += y;
  17.         }
  18.         if (((int)abs(x - y) % 2 == 1) && (abs(x - y) < minr)) {
  19.             minr = abs(x - y);
  20.         }
  21.     }
  22.     if (sum % 2 == 1) {
  23.         cout << sum;
  24.     } else if (sum % 2 == 0 && minr != 10001) {
  25.         cout << sum - minr;
  26.     } else {
  27.         cout << 0;
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement