#include #include #define REP(i,n) for(int i=0,i##_len=(n);i ans2(ll N,ll Q,vector> A,vector X){ vector x(N+1,0),w(N+1,0),Sxw(N+2,0),Sw(N+2,0); sort(All(A)); REP(i,N){ x[i+1]=A[i].first; w[i+1]=A[i].second; } REP(i,N+1){ Sxw[i+1]=Sxw[i]+x[i]*w[i]; Sw[i+1]=Sw[i]+w[i]; } vector res; REP(q,Q){ int k=lower_bound(All(A),pair(X[q],0))-A.begin()+1; res.push_back(Sxw[N+1]-2*Sxw[k]+X[q]*(2*Sw[k]-Sw[N+1])); } return res; } int main(){ ll N,Q;cin>>N>>Q; assert(1<=N&&N<=100000); assert(1<=Q&&Q<=100000); vector> A(N); set appeared; REP(i,N){ cin>>A[i].first>>A[i].second; assert(1<=A[i].first&&A[i].first<=1000000000); assert(1<=A[i].second&&A[i].second<=10000); assert(!appeared.count(A[i].first)); appeared.insert(A[i].first); } appeared.clear(); vector X(Q); REP(i,Q){ cin>>X[i]; assert(1<=X[i]&&X[i]<=1000000000); assert(!appeared.count(X[i])); appeared.insert(X[i]); } vector ans=ans2(N,Q,A,X); REP(i,Q){ cout<