#include using namespace std; #define INF 100000000 #define YJ 1145141919 #define INF_INT_MAX 2147483647 #define INF_LL 9223372036854775 #define INF_LL_MAX 9223372036854775807 #define EPS 1e-10 #define MOD 1000000007 #define MOD9 998244353 #define Pi acos(-1) #define LL long long #define ULL unsigned long long #define LD long double #define int long long #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(a) begin((a)), end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) const int MAX_N = 100; int N; struct VTNode { int v, t; bool operator < (const VTNode& vt) const { return t+v < vt.t+vt.v; } }VT[MAX_N]; bitset dp[MAX_N]; signed main() { cin >> N; REP(n,N) { cin >> VT[n].v >> VT[n].t; } sort(VT, VT+N); dp[0].set(0); REP(n,N) { //もらわない場合 dp[n+1] |= dp[n]; //貰う場合 dp[n] <<= (MAX_N*2 - VT[n].t); dp[n] >>= (MAX_N*2 - VT[n].t); dp[n] <<= VT[n].v; dp[n+1] |= dp[n]; // cerr << dp[n+1].to_string() << endl; } for(int n = 2*MAX_N-1; 0 <= n; n--) { if(dp[N][n] == 1) { cout << n << endl; return 0; } } cout << 0 << endl; return 0; }