#include using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n >> q; vector x(n),w(n); vector> p(n); REP(i,n){ cin >> x[i] >> w[i]; p[i]={x[i],w[i]}; } sort(ALL(p)); vector sx(n+1),sw(n+1); REP(i,n){ x[i]=p[i].first; w[i]=p[i].second; sw[i+1]=sw[i]+w[i]; sx[i+1]=sx[i]+x[i]*w[i]; } while(q--){ ll k;cin >> k; int u=lower_bound(ALL(x),k)-x.begin(); cout << -k*sw[n]+2*k*sw[u]+sx[n]-2*sx[u] << endl; } }