#include <bits/stdc++.h> using namespace std; int main() { int N; vector<pair<int, int>> V; cin >> N; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; V.push_back({a, b}); } sort(V.begin(), V.end(), [](pair<int, int> x, pair<int, int> y) { return x.first + x.second < y.first + y.second; }); int dp[10010] = {}; dp[0] = 1; int ans = 0; for (auto& p : V) { for (int x = 10000; x >= 0; x--) { if (dp[x] && x < p.second) { ans = max(ans, x + p.first); if (x + p.first <= 10000) dp[x + p.first] = 1; } } } cout << ans << endl; }