#include #include #include using namespace std; int N,Q; long ans[1<<17]; main() { cin>>N>>Q; vector >A(N+Q); long now=0,W=0; for(int i=0;i>A[i].first>>A[i].second; now+=(long)A[i].first*A[i].second; W-=A[i].second; } for(int i=0;i>A[N+i].first; A[N+i].second=-i; } sort(A.begin(),A.end()); int pre=0; for(pairp:A) { int x=p.first; now+=W*(x-pre); pre=x; if(p.second>0) { W+=p.second*2; } else { ans[-p.second]=now; } } for(int i=0;i