#include #include using namespace std; pair p[1009]; long long d[1009][1009], inf = 1e18; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i].second >> p[i].first; p[i].first += p[i].second; } sort(p + 1, p + n + 1); for (int i = 1; i <= n; i++) d[0][i] = inf; for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { d[i][j] = d[i - 1][j]; if (j && d[i - 1][j - 1] + p[i].second <= p[i].first) d[i][j] = min(d[i][j], d[i - 1][j - 1] + p[i].second); } } int ans = 0; for (int i = n; i >= 1; i--) if (d[n][i] != inf) { ans = i; break; } cout << ans << '\n'; return 0; }