#include<bits/stdc++.h> #define x first #define y second usingnamespacestd; constint N = 5e5 + 5; int n, sum, res; pair<int, int> p[N]; priority_queue<int> q; intmain(){ cin >> n; for (int i = 0; i < n; i++) cin >> p[i].y >> p[i].x; sort(p, p + n); for (int i = 0; i < n; i++) { if (sum + p[i].y <= p[i].x) { sum += p[i].y; res++; q.push(p[i].y); } elseif (p[i].y < q.top()) { sum -= q.top(); q.pop(); q.push(p[i].y); sum += p[i].y; } } cout << res << '\n'; return0; }