#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; vector x(n); vector w(n); rep(i, n) { cin >> x[i] >> w[i]; } ll sum_w = SUM(w); map mp_l; map mp_r; map mp_lw; map mp_rw; for (int i = 0; i < n; i++) { ll cost = 0; ll weight = 0; if (i > 0) { cost += mp_l[x[i-1]]; weight += mp_lw[x[i-1]]; cost += abs(x[i-1] - x[i]) * weight; } weight += w[i]; mp_l[x[i]] = cost; mp_lw[x[i]] = weight; } for (int i = n-1; i >= 0; i--) { ll cost = 0; ll weight = 0; if (i < n-1) { cost += mp_r[x[i+1]]; weight += mp_rw[x[i+1]]; cost += abs(x[i+1] - x[i]) * weight; } weight += w[i]; mp_r[x[i]] = cost; mp_rw[x[i]] = weight; } sort(ALL(x)); rep(i, q) { ll target; cin >> target; // 1番近い xi を求める auto itr1 = lower_bound(ALL(x), target); if (itr1 != x.begin() || itr1 == x.end()) itr1--; auto itr2 = upper_bound(ALL(x), target); if (itr2 == x.end()) itr2--; ll ans = 0; if (*itr1 < target) { ans += mp_l[*itr1] + abs(*itr1 - target) * mp_lw[*itr1]; } if (*itr2 > target) { ans += mp_r[*itr2] + abs(*itr2 - target) * mp_rw[*itr2]; } cout << ans << endl; } return 0; }