#include #include #include #include #include #include #include using namespace std; using ll = long long; int dp[100001]; int main() { int n; cin >> n; int s = 0, k = 0; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; s += b; for (int j = k; j >= 0; j--) { dp[j + a] = max(dp[j + a], dp[j] + b); } k += a; } int r = 1 << 30; for (int j = 0; j <= k; j++) { r = min(r, max(j, s - dp[j])); } cout << r << endl; return 0; }