Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<vector>
- #include<algorithm>
- #define long long long
- #define nln '\n'
- using namespace std;
- bool cmp_pair(const pair<long, long> &a, const pair<long, long> &b)
- {
- if (a.second > b.second)
- return 1;
- if (a.second < b.second)
- return 0;
- if (a.first > b.first)
- return 1;
- if (a.first < b.first)
- return 0;
- return 0;
- }
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- //freopen("lixi.inp", "r", stdin);
- long n;
- cin >> n;
- vector<pair<long, long>> a(n);
- for (auto &i : a)
- cin >> i.first >> i.second;
- // Process
- sort(a.begin(), a.end(), cmp_pair);
- long ans = 0, eng = 0;
- for (const auto &i : a){
- ans += i.first;
- eng += i.second-1;
- if (eng < 0)
- break;}
- cout << ans << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment