SHARE
TWEET

Untitled

a guest Nov 5th, 2016 197 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5.  
  6. bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
  7.     return (a.first - a.second) < (b.first - b.second);
  8. }
  9.  
  10. main()
  11. {
  12.     ios_base::sync_with_stdio(false);
  13.     cin.tie(0);
  14.     cout.tie(0);
  15.     int n;
  16.     cin >> n;
  17.     vector<pair<int, int>> s(n);
  18.     int a, b;
  19.     for (int i = 0; i < n; i++) {
  20.         cin >> a >> b;
  21.         s[i] = {a, b};
  22.     }
  23.     sort(s.begin(), s.end(), cmp);
  24.     int right = 0;
  25.     for (int i = 0; i < n; i++) {
  26.         int left = s[i].first - s[i].second;
  27.         if (left > right) {
  28.             right = left;
  29.         }
  30.         right += s[i].second;
  31.     }
  32.     cout << right;
  33. }
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