/* O(Nlog(D)+Q) */ #include using namespace std; using ll=long long; using vll=vector; using vvll=vector; vll kousa,syoko; int N,M,Q; ll X; //D[i][0]+D[i][1]+...+D[i][p-1] ll SumD(ll i,ll p){ if(p==0)return 0; return syoko[i]*p+p*(p-1)/2*kousa[i]; } //f_i(x) O(1) ll f_i(int i,ll x){ ll p; if(x<=syoko[i])p=0; else if(x>syoko[i]+kousa[i]*(M-1))p=M; else p=(x-syoko[i]-1)/kousa[i]+1; ll res=(SumD(i,M)-SumD(i,p))-SumD(i,p)+p*x-(M-p)*x; return res; } //O(logD) bool CH(int i,int j,int k){ ll L=-1,R=1e9+1; while(R-L>1){ ll M=(L+R)/2; if(f_i(j,M)<=f_i(k,M)){ L=M; } else R=M; } return f_i(i,R-1)<=f_i(j,R-1);//不要 } struct VCHT { void add(int a) { while (linesid.size()>=2&&CH(*(linesid.end() - 2), linesid.back(), a)) { linesid.pop_back(); } linesid.push_back(a); } ll get(ll x) { while (linesid.size() >= 2 && f_i(linesid.front(),x) > f_i(linesid[1],x)) { linesid.pop_front(); } return linesid.front(); } deque linesid; }; int main(){ cin>>N>>M; kousa.resize(N); syoko.resize(N); for(int i=0;i>syoko[i]>>kousa[i]; VCHT V; for(int i=0;i>Q>>X; vll C(N); for(int i=0;i>C[i]; vector AN(Q); for(int q=0;q1e9+5)X=1e9+5; } for(int q=0;q