#include #include #include using namespace std; using ll = long long; #include int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; vector v(n),t(n); for(int i = 0;i>v[i]>>t[i]; ll sum = 0; for(int i = 0;i idx(n); for(int i = 0;i t[j] + v[j] - 1; }); auto calc = [&](ll now) { set all; all.insert(now); for(int i = 0;i=use) all.insert(use-v[ni]); } } return all.count(0); }; while(right-left>1){ ll mid = (right+left) / 2; if(calc(mid)) left = mid; else right = mid; } cout<