#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; int main() { int N; cin >> N; vector a(N); for (int i = 0; i < N; i++) cin >> a[i].second >> a[i].first; sort(a.begin(), a.end()); vector V(N), T(N); for (int i = 0; i < N; i++) { V[i] = a[i].second; T[i] = a[i].first; } vector dp = vector(20001); dp[0] = true; for (int i = 0; i < N; i++) { for (int j = T[i] - 1; j >= 0; j--) if (dp[j]) dp[j + V[i]] = true; } for (int j = 20000; j >= 0; j--) { if (dp[j]) { cout << j << endl; break; } } }