#include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; int N; int v_[10000], t_[10000]; int v[10000], t[10000]; P p[10000]; int ans; bool ok[10001]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N; for(int i = 0; i < N; i++){ cin >> v_[i] >> t_[i]; p[i] = P(v_[i]+t_[i], i); } sort(p, p+N); for(int i = 0; i < N; i++){ int idx = p[i].second; v[i] = v_[idx]; t[i] = t_[idx]; } ok[0] = true; for(int i = 0; i < N; i++){ vector u; for(int j = 0; j <= 10000; j++){ if(ok[j]){ u.push_back(j); if(j < t[i]) u.push_back(j+v[i]); } } for(int j : u) { ok[j] = true; ans = max(ans, j); } } cout << ans << endl; }