/* -*- coding: utf-8 -*- * * 54.cc: No.54 Happy Hallowe'en - 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 = 10000; const int MAX_T = 10000; /* typedef */ struct VT { int v, t, sum; VT() {} VT(int _v, int _t): v(_v), t(_t) { sum = v + t; } bool operator<(const VT &vt) const { return sum < vt.sum; } }; /* global variables */ VT vts[MAX_N]; bool dp[MAX_N + 1][MAX_T]; /* subroutines */ /* main */ int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int vi, ti; cin >> vi >> ti; vts[i] = VT(vi, ti); } sort(vts, vts + n); dp[0][0] = true; int ans = -1; for (int i = 0; i < n; i++) { int &vi = vts[i].v, &ti = vts[i].t; for (int j = 0; j < MAX_T; j++) if (dp[i][j]) { dp[i + 1][j] = true; if (j < ti) { int j0 = j + vi; if (ans < j0) ans = j0; if (j0 < MAX_T) dp[i + 1][j0] = true; } } } printf("%d\n", ans); return 0; }