#include #include #include #include #include #include #include #include #include #include using namespace std; #define PAIR pair int main() { long long N; cin >> N; vector w(N), s(N); for (int i = 0; i < N; i++) cin >> w[i] >> s[i]; vector sum(N); for (int i = 0; i < N; i++) { sum[i].first = w[i] + s[i]; sum[i].second = w[i]; } sort(sum.begin(), sum.end()); vector> dp(N + 1, vector(N + 1, 1LL << 60)); for (int i = 0; i <= N; i++) { if (i == 0) { dp[i][0] = 0; continue; } for (int j = 0; j <= N; j++) { if (j == 0) dp[i][j] = 0; else { if (dp[i - 1][j - 1] > sum[i - 1].first - sum[i - 1].second) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + sum[i - 1].second); } } } } long long max_size = 0; for (int i = 1; i <= N; i++) { if (dp[N][i] != 1LL << 60) max_size = i; } cout << max_size << endl; }