#include int main() { int N; std::cin >> N; using P = std::pair; std::vector

D(N); for (int i = 0; i < N; i++) { std::cin >> D[i].first >> D[i].second; } std::sort(D.begin(), D.end(), [](const P& p1, const P& p2) { return p1.first + p1.second < p2.first + p2.second; }); std::bitset<20001> dp; dp[0] = true; for (const auto& p : D) { for (int i = 0; i < p.second; i++) { dp[i + p.first] = dp[i] | dp[i + p.first]; } } for (int i = 20000; i >= 0; i--) { if (dp[i]) { return std::cout << i << std::endl, 0; } } return 0; }