#include #include #include #include #include #define INF (2 << 24) using namespace std; int n; bool dp[20001]; bool chk[10001]; vector > vt; int main(){ cin >> n; for(int i = 0; i < n; i++){ int v, t; cin >> v >> t; vt.push_back(make_pair(v, t)); } sort(vt.begin(), vt.end()); dp[0] = true; for(int j = 0; j < n; j++){ for(int i = vt[j].second - 1; i >= 0; i--){ if(dp[i] && i < vt[j].second) dp[i + vt[j].first] = true; } } for(int i = 20000; i >= 0; i--){ if(dp[i]){ cout << i << endl; break; } } }