#include #include #include template std::vector vec(int len, T elem) { return std::vector(len, elem); } void solve() { int n; std::cin >> n; std::vector> ps(n); for (auto& p : ps) { int a, b; std::cin >> a >> b; p = std::make_pair(a, b - a); } int ok = 2000, ng = 0; while (ok - ng > 1) { int mid = (ok + ng) / 2; std::vector> graph(n); for (int v = 0; v < n; ++v) { for (int u = 0; u < n; ++u) { if (u == v || ps[v].second + ps[u].first > mid) continue; graph[v].push_back(u); } } auto dp = vec(n, vec(1 << n, false)); for (int i = 0; i < n; ++i) { dp[i][1 << i] = true; } for (int b = 0; b < (1 << n); ++b) { for (int i = 0; i < n; ++i) { if (!dp[i][b]) continue; for (auto j : graph[i]) { if ((b >> j) & 1) continue; dp[j][b | (1 << j)] = true; } } } if (std::any_of(dp.begin(), dp.end(), [](const auto& v) { return v.back(); })) { ok = mid; } else { ng = mid; } } std::cout << ok << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }