fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. void solve()
  6. {
  7. int n, m; cin >> n >> m;
  8. vector<pair<int, int>> v(n);
  9. for (auto&i:v)
  10. cin >> i.first >> i.second;
  11. sort(v.begin(), v.end(), [&](pair<int, int> i, pair<int, int> j)->bool
  12. {
  13. if (i.second > j.second)
  14. return true;
  15. else if (i.second < j.second)
  16. return false;
  17. else
  18. return i.first > j.first;
  19. });
  20. ll time = 0, ans = 0;
  21. for (auto&i:v)
  22. if (time+i.first <= m)
  23. ans+=i.second, time++;
  24. cout << ans;
  25. }
  26.  
  27. int main()
  28. {
  29. #ifndef ONLINE_JUDGE
  30. freopen("input.txt", "r", stdin);
  31. freopen("output.txt", "w", stdout);
  32. freopen("Errors.txt", "w", stderr);
  33. #endif
  34. ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  35. int t = 1;
  36. // cin >> t;
  37. while (t--)
  38. {
  39. solve();
  40. if (t) cout << '\n';
  41. }
  42. cout << '\n';
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
0