#include #include #include using namespace std; int main() { int N; cin >> N; vector dp(10000 * 10000 + 1, false); vector> v(N); for (int n = 0; n < N; ++n) { cin >> v[n].first >> v[n].second; } sort(v.begin(), v.end()); dp[0] = true; int ans = 0; for (int n = 0; n < N; ++n) { int V = v[n].first; int T = v[n].second; for (int i = T - 1; i >= 0; --i) { if (dp[i]) { dp[i + V] = true; ans = max(ans, i + V); } } } cout << ans << endl; }