Iamtui1010

lixi.cpp

Jan 13th, 2022
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<vector>
  4. #include<algorithm>
  5.  
  6. #define long long long
  7. #define nln '\n'
  8.  
  9. using namespace std;
  10.  
  11. bool cmp_pair(const pair<long, long> &a, const pair<long, long> &b)
  12. {
  13.     if (a.second > b.second)
  14.         return 1;
  15.     if (a.second < b.second)
  16.         return 0;
  17.     if (a.first > b.first)
  18.         return 1;
  19.     if (a.first < b.first)
  20.         return 0;
  21.     return 0;
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27.     cin.tie(0)->sync_with_stdio(0);
  28.     cout.tie(0)->sync_with_stdio(0);
  29.     //freopen("lixi.inp", "r", stdin);
  30.     long n;
  31.     cin >> n;
  32.     vector<pair<long, long>> a(n);
  33.     for (auto &i : a)
  34.         cin >> i.first >> i.second;
  35.     // Process
  36.     sort(a.begin(), a.end(), cmp_pair);
  37.     long ans = 0, eng = 0;
  38.     for (const auto &i : a){
  39.         ans += i.first;
  40.         eng += i.second-1;
  41.         if (eng < 0)
  42.             break;}
  43.     cout << ans << nln;
  44.     return 0;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment