#include using namespace std; #define REP(i,a,b) for(i=a;i'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} template void reader(T *x, S *y){reader(x);reader(y);} void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} template void writerLn(T x){writer(x,'\n');} template void sort(int N, T1 a[], T2 b[], void *mem){int i;pair *r=(pair*)mem;rep(i,N)r[i].first=a[i],r[i].second=b[i];sort(r,r+N);rep(i,N)a[i]=r[i].first,b[i]=r[i].second;} template void sort(int N, T1 a[], T2 b[], T3 c[], void *mem){int i;pair > *r=(pair >*)mem;rep(i,N)r[i].first=a[i],r[i].second.first=b[i],r[i].second.second=c[i];sort(r,r+N);rep(i,N)a[i]=r[i].first,b[i]=r[i].second.first,c[i]=r[i].second.second;} void bitOR(ull a[], ull b[], int stA, int stB, int len){int i,B,E,R,Y,X,G,Z;static ull p[65],q[65];static int f=0;if(!f){f=1;p[0]=0;rep(i,64)p[i+1]=(p[i]<<1)|1ULL;rep(i,65)q[i]=p[64]^p[i];}B=stA/64;E=stA%64;R=(stA+len)/64;Y=(stA+len)%64;X=stA-stB;G=X/64;Z=X%64;if(Z<0)Z+=64,G--;if(stA>stB){if(B==R){if(Z)b[B-G-1]|=(a[B]&p[Y]&q[E])<<(64-Z);b[B-G]|=(a[B]&p[Y]&q[E])>>Z;}else{if(Z)b[B-G-1]|=(a[B]&q[E])<<(64-Z);b[B-G]|=(a[B]&q[E])>>Z;REP(i,B+1,R){if(Z)b[i-G-1]|=a[i]<<(64-Z);b[i-G]|=a[i]>>Z;}if(Z)b[R-G-1]|=(a[R]&p[Y])<<(64-Z);b[R-G]|=(a[R]&p[Y])>>Z;}}else{if(B==R){b[B-G]|=(a[B]&p[Y]&q[E])>>Z;if(Z)b[B-G-1]|=(a[B]&p[Y]&q[E])<<(64-Z);}else{b[R-G]|=(a[R]&p[Y])>>Z;if(Z)b[R-G-1]|=(a[R]&p[Y])<<(64-Z);for(i=R-1;i>B;i--){b[i-G]|=a[i]>>Z;if(Z)b[i-G-1]|=a[i]<<(64-Z);}b[B-G]|=(a[B]&q[E])>>Z;if(Z)b[B-G-1]|=(a[B]&q[E])<<(64-Z);}}} char memarr[77000000]; void *mem = memarr; int N, V[20000], T[20000], val[20000]; ull dp[400]; int main(){ int i, j, k, loop; int res=0, tmp; reader(&N); rep(i,N) reader(V+i, T+i); rep(i,N) val[i] = T[i]+V[i]; sort(N, val, T, V, mem); rep(i,400) dp[i] = 0; dp[0] = 1; rep(k,N) bitOR(dp, dp, 0, V[k], T[k]); for(i=20000;i>=0;i--) if(dp[i/64]&(1ULL<<(i%64))) { res = i; break; } writerLn(res); return 0; }