#include using namespace std; typedef long long int ll; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector> v(n); ll sum=0; for(int i=0;i> v[i].first; } for(int i=0;i> v[i].second; sum+=v[i].second; } sort(v.begin(), v.end()); sum=(sum+1)/2; for(int i=0;i=v[i].second){ sum-=v[i].second; } else{ sum=v[i].first; break; } } ll res=0; for(int i=0;i