#include using namespace std; const int MAX_N = 100; const int MAX_B = 1000; const int INF = (1 << 28); const int MAX_SUM = MAX_B * MAX_N; int dp[MAX_SUM + 1]; int main() { int N; cin >> N; int A[MAX_N], B[MAX_N]; for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; } for (int sum = 1; sum <= MAX_SUM; sum++) { dp[sum] = INF; } int ans = INF; for (int i = 0; i < N; i++) { for (int sum = MAX_SUM; sum >= 0; sum--) { dp[sum] = dp[sum] + A[i]; if (sum - B[i] >= 0) { dp[sum] = min(dp[sum], dp[sum - B[i]]); } if (i == N - 1) ans = min(ans, max(sum, dp[sum])); } } cout << ans << endl; return 0; }