// yukicoder: No.710 チーム戦 // 2019.8.4 bal4u #include #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } #define MAX 100005 int dp[MAX]; int main() { int i, j, N, ma, a, b; memset(dp, 0x077, sizeof(dp)); N = in(); dp[0] = 0, ma = 0; for (i = 1; i <= N; i++) { a = in(), b = in(); for (j = ma; j >= 0; j--) if (dp[j] < MAX) { if (dp[j+a] > dp[j]) dp[j+a] = dp[j]; dp[j] += b; } ma += a; } a = 100005; for (i = 0; i <= ma; i++) if (dp[i] < MAX) { b = i; if (dp[i] > b) b = dp[i]; if (b < a) a = b; } printf("%d\n", a); return 0; }