#include #include #include using namespace std; int N; long M; long A[1<<17],B[1<<17]; int Q; long X; int C[1<<17]; long s(long a,long b,long n) { long ret=a*n; ret+=n*(n-1)/2*b; return ret; } long f(int id,long R) { if(A[id]>=R) { return s(A[id],B[id],M)-R*M; } else if(A[id]+(M-1)*B[id]<=R) { return R*M-s(A[id],B[id],M); } //A[id]+k*B[id]<=R //k<=(R-A[id])/B[id] long k=(R-A[id])/B[id]; assert(0<=k&&k1) { long mid=(l+r)/2; if(f(j,mid)>N>>M; for(int i=0;i>A[i]>>B[i]; cin>>Q>>X; for(int i=0;i>C[i]; vectorP; P.push_back(0); for(int i=1;i=2) { long a=g(P[P.size()-2],P[P.size()-1]); long b=g(P[P.size()-1],i); if(b<=a)P.pop_back(); else break; } P.push_back(i); } int idx=0; for(int q=0;qtst)cur=tst,idx++; else break; } cout<