#include using namespace std; typedef long long ll; typedef pair P; #define MAX_N 100005 vector X; ll N,D; ll a[MAX_N],b[MAX_N]; ll c[MAX_N]; P d[MAX_N]; ll INF = (1LL<<50); ll tree[(1<<18)]; ll getMax(int a,int b,int k=0,int l=0,int r=(1<<17)){ if(b<=l || r<=a)return -INF; if(a<=l && b<=r)return tree[k]; int m=(l+r)/2; return max( getMax(a,b,k*2+1,l,m) , getMax(a,b,k*2+2,m,r) ); } void update(int i,ll x){ i+=(1<<17)-1; tree[i]=x; while(i){ i=(i-1)/2; tree[i]=max(tree[i*2+1],tree[i*2+2]); } } ll getSum(int a,int b){ return c[b]-c[a]; } P solve(){ fill(d,d+MAX_N, P(INF,INF) ); d[0]=P(0,0); for(int i=0;i