#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll=long long; template using V = vector; template using P = pair; using vll = V; using vvll = V; #define rep(i, k, n) for (ll i=k; i<(ll)n; ++i) #define REP(i, n) rep(i, 0, n) #define ALL(v) v.begin(),v.end() template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; } template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; } #define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<> n >> q; V< P > xw(n); for (ll i = 0; i < n; i++) cin >> xw[i].first >> xw[i].second; sort(ALL(xw)); vll lwacc(n + 1, 0), rwacc(n + 1, 0); vll lcost(n, 0), rcost(n, 0); for (ll i = 0; i < n; i++) { lwacc[i + 1] = lwacc[i] + xw[i].second; } for (ll i = n - 1; i >= 0; i--) { rwacc[i] = rwacc[i + 1] + xw[i].second; } for (ll i = 1; i < n; i++) { lcost[i] = lcost[i - 1] + lwacc[i] * (xw[i].first - xw[i - 1].first); } for (ll i = n - 2; i >= 0; i--) { rcost[i] = rcost[i + 1] + rwacc[i + 1] * (xw[i + 1].first - xw[i].first); } while (q-->0) { ll x; cin >> x; ll idx = lower_bound(ALL(xw), make_pair(x, 0LL)) - xw.begin(); if (xw[idx].first == x) { cout << lcost[idx] + rcost[idx] << '\n'; } else { ll cost = lcost[idx - 1] + rcost[idx] + (x - xw[idx - 1].first) * lwacc[idx] + (xw[idx].first - x) * rwacc[idx]; cout << cost << '\n'; } } return 0; }