#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(int i=0; i<(n); i++) #define RREP(i, n) for(int i=(n-1); i>=0; i--) #define ALL(a) (a).begin(),(a).end() struct home { int v, t; }; int N; vector homes; bool comp(home a, home b) { return a.t + a.v < b.t + b.v; } signed main() { cin >> N; homes.resize(N); REP(i,N) cin >> homes[i].v >> homes[i].t; bool dp[20000] = {0}; dp[0] = true; sort(ALL(homes), comp); REP(i,N) { RREP(j,homes[i].t) { dp[j+homes[i].v] |= dp[j]; } } RREP(i,20000) { if (dp[i]) { cout << i << endl; break; } } return 0; }