#include using namespace std; #define rep(i,n) for(int i=0;i=0;i--) int n; pair P[200]; int ans; int aa, bb; int rest[200]; void dfs(int i) { int ma = max(aa, bb); int mi = min(aa, bb); if (ma + (rest[i] - (ma - mi)) / 2 >= ans) return; if (i == n) { if (ans > ma) { ans = ma; // out(ans); } return; } // i を A が aa += P[i].first; dfs(i+1); aa -= P[i].first; // i を B が bb += P[i].second; dfs(i+1); bb -= P[i].second; } int solve() { { int aa = 0, bb = 0; rep(i, n) { if (P[i].first < P[i].second) aa += P[i].first; else bb += P[i].second; } ans = max(aa, bb); } auto cmp = [&](pair lhs, decltype(lhs) rhs) -> bool { return lhs.first + lhs.second > rhs.first + rhs.second; }; sort(P, P+n, cmp); rrep(i, n-1) { rest[i] = rest[i+1] + min(P[i+1].first, P[i+1].second); } dfs(0); return ans; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> n; rep(i, n) { cin >> P[i].first >> P[i].second; } int ans = solve(); cout << ans << endl; return 0; }