#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int N,Q; pair x[1 << 17],X[1 << 17]; long long W[1 << 17],WX[1 << 17],res[1 << 17]; void solve() { cin >> N >> Q; for(int i = 0;i < N;i++) cin >> x[i].first >> x[i].second; sort(x,x+N); for(int i = 0;i < N;i++) { W[i+1] = W[i] + x[i].second; WX[i+1] = WX[i] + (long long)x[i].first*x[i].second; } for(int i = 0;i < Q;i++) cin >> X[i].first,X[i].second = i; sort(X,X+Q); int ai = 0; for(int i = 0;i < Q;i++) { while(ai < N && x[ai].first < X[i].first) ai++; int qi = X[i].second; res[qi] += W[ai]*X[i].first - WX[ai]; res[qi] += WX[N]-WX[ai] - (W[N]-W[ai])*X[i].first; } for(int i = 0;i < Q;i++) cout << res[i] << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; //cin >> tt; while(tt--) solve(); }