#include #include #include using namespace std; typedef pair P; P p[10010]; bool dp[20010] = {true}; int main(){ int n; cin >> n; for (int i = 0; i < n; i++){ cin >> p[i].second >> p[i].first; p[i].first += p[i].second; } sort(p, p + n); for (int i = 0; i < n; i++){ for (int j = p[i].first-p[i].second - 1; j >= 0; j--){ dp[j + p[i].second] |= dp[j]; } } int res = 0; for (int i = 0; i < 20010; i++){ if (dp[i])res = i; } cout << res << endl; }