#include #include #include #include #include #include #include #include #include #include using namespace std; #define int long long int MOD = 1000000007; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector A(N); vector B(N); int res = 0; for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; } int INF = (int)1 << 60; vector dp(100005, INF); vector ndp(100005, INF); dp[0] = 0; ndp[0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= 100000; j++) { ndp[j] = INF; } for (int j = 0; j + A[i] <= 100000; j++) { if (j + A[i] <= 100000) { ndp[j + A[i]] = min(ndp[j + A[i]], dp[j]); } ndp[j] = min(ndp[j], dp[j] + B[i]); } swap(dp, ndp); } res = INF; for (int j = 0; j <= 100000; j++) { res = min(res, max(j, dp[j])); } cout << res << endl; }