Iamtui1010

practice.cpp

Jan 12th, 2022
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 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.first > b.first)
  14.         return 1;
  15.     if (a.first < b.first)
  16.         return 0;
  17.     if (a.second > b.second)
  18.         return 0;
  19.     if (a.second < b.second)
  20.         return 1;
  21.     return 0;
  22. }
  23.  
  24. int main()
  25. {
  26.     cin.tie(0)->sync_with_stdio(0);
  27.     cout.tie(0)->sync_with_stdio(0);
  28.     //freopen("practice.inp", "r", stdin);
  29.     long n, t;
  30.     cin >> n >> t;
  31.     vector<pair<long, long>> a(n);
  32.     for (auto &i : a)
  33.         cin >> i.first >> i.second;
  34.     // Process
  35.     sort(a.rbegin(), a.rend(), cmp_pair);
  36.     long ans = 0;
  37.     for (long i = 0; i < n; ++i)
  38.     {
  39.         if (t < a[i].first)
  40.             break;
  41.         ++ans;
  42.         t += a[i].second;
  43.     }
  44.     cout << ans << nln;
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment