#include using namespace std; #define rep(i,a,b) for(int i=a;i VT[10101]; bool dp[2][10101]; bool comp(pair a, pair b) { return (a.second + a.first) < (b.first + b.second); } int main() { cin.tie(0); ios::sync_with_stdio(false); while (cin >> N) { rep(i, 0, N) { int v, t; cin >> v >> t; VT[i] = make_pair(v, t); } sort(VT, VT + N, comp); rep(i, 0, 2) rep(j, 0, 10101) dp[i][j] = false; dp[0][0] = true; int ans = 0; rep(i, 0, N) { int ii = i + 1; rep(j, 0, 10101) dp[ii % 2][j] = false; rep(j, 0, 10101) if (dp[i % 2][j]) { dp[ii % 2][j] = true; if (j < VT[i].second) { int jj = j + VT[i].first; ans = max(ans, jj); if(jj < 10000) dp[ii % 2][jj] = true; } } } cout << ans << endl; } }