#include #define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++) const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector vi; typedef vector vll; typedef pair pii; const int MAXN = 10010; struct present { int v; int t; present() {} present(int v, int t) : v(v), t(t) {} bool operator<(const present& rhs) const { return v+t < rhs.v+rhs.t; } }; present p[MAXN]; bool dp[2][2*MAXN]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; for (int i = 0; i < N; i++) { int v, t; cin >> v >> t; p[i] = present(v, t); } sort(p, p+N); memset(dp, 0, sizeof(dp)); dp[0][0] = true; for (int i = 0; i < N; i++) { int cur = i%2; int tar = cur^1; for (int t = 0; t <= MAXN; t++) { if (!dp[cur][t]) continue; dp[tar][t] = true; int tmp = t+p[i].v; if (t < p[i].t) dp[tar][tmp] = true; } } int ans = 0; for (int i = 0; i < 2*MAXN; i++) { if (dp[0][i] || dp[1][i]) ans = i; } cout << ans << endl; return 0; }