#include #include int main() { int N; std::cin >> N; std::vector A(N), B(N); for (int i = 0; i < N; i++) { std::cin >> A[i] >> B[i]; } constexpr int INF = 1 << 30; std::vector> dp(1 << N, std::vector(N, INF)); for (int i = 0; i < N; i++) { dp[1 << i][i] = 0; } for (int i = 0; i < (1 << N); i++) { for (int j = 0; j < N; j++) { if ((i & (1 << j)) == 0) { continue; } const int p = i - (1 << j); if (p == 0) { continue; } for (int k = 0; k < N; k++) { if (p & (1 << k)) { dp[i][j] = std::min(dp[i][j], std::max(dp[p][k], A[j] - A[k] + B[k])); } } } } int ans = INF; for (int j = 0; j < N; j++) { ans = std::min(ans, dp[(1 << N) - 1][j]); } std::cout << ans << std::endl; return 0; }