#include #define rep(i,n) for (int i = 0; i < n; ++i) #define ALL(c) (c).begin(), (c).end() #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) using namespace std; typedef long long ll; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = 1e9; const long long INFL = 1LL<<60; int main() { int n, q; cin >> n >> q; map xw; rep(i, n) { ll x, w; cin >> x >> w; xw[x] += w; } int N = xw.size(); vector x; vector w; for (auto& v : xw) { x.push_back(v.first); w.push_back(v.second); } vector lc(N, 0), lw(N, 0); vector rc(N, 0), rw(N, 0); rep(i, N) { lw[i] += w[i]; if (i > 0) { lw[i] += lw[i-1]; lc[i] = lc[i-1] + (x[i] - x[i-1]) * lw[i-1]; } } for (int i = N-1; i >= 0; i--) { rw[i] += w[i]; if (i < N-1) { rw[i] += rw[i+1]; rc[i] = rc[i+1] + (x[i+1] - x[i]) * rw[i+1]; } } rep(i, q) { ll ans = 0; ll X; cin >> X; auto itr = lower_bound(ALL(x), X); int idx = itr - x.begin(); if (x[N-1] <= X) { ans = lc[N-1] + (X - x[N-1]) * lw[N-1]; } else if (X <= x[0]) { ans = rc[0] + (x[0] - X) * rw[0]; } else if (x[idx] == X) { ans = lc[idx] + rc[idx]; } else { ans += lc[idx-1] + (X - x[idx-1]) * lw[idx-1]; ans += rc[idx] + (x[idx] - X) * rw[idx]; } cout << ans << endl; } return 0; }