Advertisement
kostes

Untitled

Jan 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define fst first
  4. #define snd second
  5. #define all(c) c.begin(),c.end()
  6. using namespace std;
  7. typedef long long ll;
  8. const ll INF64 = 1e18 + 1337;
  9. const int INF32 = 1e9 + 228;
  10. const int MOD = 1e9 + 7;
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(0);
  14. #ifndef __WIN32
  15. ifstream cin("input.txt");
  16. ofstream cout("output.txt");
  17. #endif
  18. cin.tie(0);cout.tie(0);
  19.  
  20. ll n, _t;
  21. cin >> n >> _t;
  22. multiset<ll> s;
  23. ll sum = 0;
  24. ll ans = 0;
  25. for(int i = 0; i < n; i++)
  26. {
  27. ll x, t;
  28. cin >> x >> t;
  29. while(sum + x > _t)
  30. {
  31. auto it = prev(s.end());
  32. sum -= *it;
  33. s.erase(it);
  34. }
  35. if(sum + x + t <= _t)
  36. {
  37. s.insert(t);
  38. sum += t;
  39. }
  40. ans = max(ans, (ll)s.size());
  41. }
  42. cout << ans;
  43.  
  44.  
  45.  
  46. #ifndef __WIN32
  47. cin.close();
  48. cout.close();
  49. #endif
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement