/* -*- coding: utf-8 -*- * * 771.cc: No.771 しおり - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 18; const int NBITS = 1 << MAX_N; const int INF = 1 << 30; /* typedef */ /* global variables */ int as[MAX_N], bs[MAX_N]; int dp[NBITS][MAX_N]; /* subroutines */ inline void setmin(int &a, int b) { if (a > b) a = b; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", as + i, bs + i); int nbits = 1 << n; for (int bits = 0; bits < nbits; bits++) fill(dp[bits], dp[bits] + n, INF); for (int i = 0, bi = 1; i < n; i++, bi <<= 1) dp[bi][i] = 0; for (int bits = 1; bits < nbits; bits++) for (int i = 0; i < n; i++) for (int j = 0, bj = 1; j < n; j++, bj <<= 1) if (! (bits & bj)) setmin(dp[bits | bj][j], max(dp[bits][i], bs[i] - as[i] + as[j])); int mind = INF; for (int i = 0; i < n; i++) setmin(mind, dp[nbits - 1][i]); printf("%d\n", mind); return 0; }