Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
- return (a.first - a.second) < (b.first - b.second);
- }
- main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin >> n;
- vector<pair<int, int>> s(n);
- int a, b;
- for (int i = 0; i < n; i++) {
- cin >> a >> b;
- s[i] = {a, b};
- }
- sort(s.begin(), s.end(), cmp);
- int right = 0;
- for (int i = 0; i < n; i++) {
- int left = s[i].first - s[i].second;
- if (left > right) {
- right = left;
- }
- right += s[i].second;
- }
- cout << right;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement