#include int dp[100][100*1000]; int min(int a, int b){ return (ab)?a:b;} int main(){ //dp[i][j]: i banme made de yukioga j byou inai kakaru nakade yukionnnano futann keigennno saidait //dp[i][j] = max{ dp[i-1][j-taro(i)] + onnna(i) , dp[i-1][j]} int N; int A[100],B[100]; int sumB=0; int sumA=0; scanf("%d",&N); for(int i = 0; i < N; i++){ scanf("%d %d",A+i,B+i); sumB += B[i]; sumA += A[i]; } for(int j = 0; j < sumA; j++){ dp[0][j] = 0; } dp[0][A[0]] = B[0]; for(int i = 1; i < N; i++){ for( int j = 0; j < sumA; j++){ if(j >= A[i]) dp[i][j] = max ( dp[i-1][j-A[i]]+B[i] , dp[i-1][j] ); else dp[i][j] = dp[i-1][j]; } } //#define DEBUG #ifdef DEBUG for(int i = 0; i < N; i++){ for(int j = 0; j < sumA; j++){ printf("%d,",dp[i][j]); }puts(""); } #endif int minAns=10000000; for(int j = 0; j < sumA; j++){ minAns = min(minAns , max(j, sumB-dp[N-1][j])); } #ifdef DEBUG for(int j = 0; j < sumA; j++) printf("(%d,%d,%d)\n",j,sumB+dp[N-1][j],max(j, sumB-dp[N-1][j])); #endif printf("%d\n",minAns); }