Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define fst first
- #define snd second
- #define all(c) c.begin(),c.end()
- using namespace std;
- typedef long long ll;
- const ll INF64 = 1e18 + 1337;
- const int INF32 = 1e9 + 228;
- const int MOD = 1e9 + 7;
- int main()
- {
- ios_base::sync_with_stdio(0);
- #ifndef __WIN32
- ifstream cin("input.txt");
- ofstream cout("output.txt");
- #endif
- cin.tie(0);cout.tie(0);
- ll n, _t;
- cin >> n >> _t;
- multiset<ll> s;
- ll sum = 0;
- ll ans = 0;
- for(int i = 0; i < n; i++)
- {
- ll x, t;
- cin >> x >> t;
- while(sum + x > _t)
- {
- auto it = prev(s.end());
- sum -= *it;
- s.erase(it);
- }
- if(sum + x + t <= _t)
- {
- s.insert(t);
- sum += t;
- }
- ans = max(ans, (ll)s.size());
- }
- cout << ans;
- #ifndef __WIN32
- cin.close();
- cout.close();
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement