#include "bits/stdc++.h" using namespace std; #define MAX 25000 bool dp[MAX]; int main(){ int N; cin >> N; vector> temp(N); for (int i = 0; i < N; i++) { int v, t; cin >> v >> t; temp[i] = make_pair(v + t, t); } sort(temp.begin(), temp.end()); vector V(N), T(N); for (int i = 0; i < N; i++) { V[i] = temp[i].first - temp[i].second; T[i] = temp[i].second; } dp[0] = true; for (int i = 0; i < N; i++) { for (int j = T[i] - 1; j >= 0; j--) { dp[j + V[i]] |= dp[j]; } } for (int i = MAX - 1; i >= 0; i--) { if (dp[i]){ cout << i << endl; return 0; } } }