#include #include #include #include #include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) using namespace std; int main() { int n; cin >> n; vector v(n), t(n); repeat (i,n) cin >> v[i] >> t[i]; vector ix(n); whole(iota, ix, 0); whole(iota, ix, 0); whole(sort, ix, [&](int i, int j) { return v[i] + t[i] < v[j] + t[j]; }); auto dp = make_unique >(); (*dp)[0] = true; for (int i : ix) { auto it = make_unique >(); it->flip(); *it <<= t[i]; it->flip(); *it &= *dp; *it <<= v[i]; *dp |= *it; } for (int i = dp->size() - 1; i >= 0; -- i) { if ((*dp)[i]) { cout << i << endl; break; } } return 0; }