#include #define int ll using namespace std; #define rep(i,n) for(int i=0;i=0;i--) #define rng(i,c,n) for(int i=c;i #define _3TpP2FO ios::sync_with_stdio(0),cin.tie(0); typedef long long ll; typedef vector vi; typedef pair pii; void print(){cout<<'\n';} template void print(const h&v,const t&...u){cout<>n; vec(pii) a(n); rep(i,n){ cin>>a[i].fi>>a[i].se; } sort(all(a)); int lk=-inf; rep(i,n){ auto [l,r]=a[i]; // l - i - 1 <= k lk=max(lk,l-i-1); } //print(lk); auto f=[&](int k)->int{ vec(vi) adqry(n+1); rep(i,n){ auto [l,r]=a[i]; l-=k,r-=k; l=max(l,1ll); r=min(r,n); if(l>r) return 0; adqry[l].pb(r); } priority_queue> pq; rng(l,1,n+1){ for(auto r:adqry[l]) pq.push(r); while(sz(pq) and pq.top()