#include #include using namespace std; using namespace atcoder; using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; #define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++) #define RREP(i, init, n) for(int i = (int)(init); i >= (int)(n); i--) #define All(A) A.begin(), A.end() #define rAll(A) A.rbegin(), A.rend() #define vi vector #define vl vector #define vvi vector> #define vvl vector> #define pint pair #define plong pair int N; vvi V; void solve() { sort(All(V)); vi dp(20010, 0); dp[0] = 1; REP(i, 0, N) { int t = V[i][1]; int v = V[i][2]; // cout << t << " " << v << endl; RREP(i, t - 1, 0) { if(dp[i] == 1) { dp[i + v] = 1; } } } int ans = 0; REP(i, 0, 20010) { if(dp[i] == 1) ans = i; } cout << ans << endl; } int main() { cin >> N; V.resize(N); REP(i, 0, N) { int v, t; cin >> v >> t; V[i] = {v + t, t, v}; } solve(); }