#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAX_N 510 #define PI 3.141592653589 #define ESP 1e-20 #define BS 10 #define MOD 1000000007 #define ZERO 10001 #define YJSNPI 810 //#define INF (1 << 30) #define ADD(a, b) a = (a + (ll)b) % MOD #define MUL(a, b) a = (a * (ll)b) % MOD #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) using namespace std; typedef long long ll; typedef pair pi; typedef unsigned long long ull; int N; int V[10010], T[10010]; int C[10010]; int dp[2][20010]; bool comp(int a, int b) { return V[a] + T[a] < V[b] + T[b]; } int main() { scanf("%d", &N); for(int i = 0; i < N; i++) { scanf("%d%d", &V[i], &T[i]); C[i] = i; } sort(C, C + N, comp); dp[0][0] = true; for(int i = 0; i < N; i++) { int now = i % 2, next = 1 - now; for(int j = 0; j <= 20000; j++) { if(!dp[now][j]) continue; dp[next][j] = true; if(j < T[C[i]]) dp[next][j + V[C[i]]] = true; dp[now][j] = false; } } for(int i = 20000; i >= 0; i--) { if(dp[N % 2][i]) { printf("%d\n", i); return 0; } } }