#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll=long long; using ld=long double; using P=pair; #define MOD 998244353LL #define INF 1000000000LL #define EPS 1e-10 #define FOR(i,n,m) for(ll i=n;i<(ll)m;i++) #define REP(i,n) FOR(i,0,n) #define DUMP(a) REP(d,a.size()){cout<> n; vector a(n); vector b(n); REP(i, n) cin >> a[i] >> b[i]; vector> dp((1ll << n), vector(n, INF)); REP(bit, (1ll << n)) REP(i, n) { bitset<18> bi(bit); if(bi[i] == 0) continue; if(bi.count() == 1) { dp[bit][i] = 0; continue; } bi[i] = 0; REP(j, n) { if(bi[j] == 0 || j == i) continue; dp[bit][i] = min(dp[bit][i], max(dp[bi.to_ullong()][j], a[i] + (b[j] - a[j]))); } } ll ans = INF; REP(i, n) ans = min(ans, dp[(1ll << n) - 1][i]); cout << ans << endl; return 0; } /* --------------------------------------- */