//yukicoder@cpp17 #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; using P = pair; const ll MOD = 998244353; const ll MODx = 1000000007; const int INF = (1<<30)-1; const ll LINF = (1LL<<62LL)-1; const double EPS = (1e-10); P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}}; P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; template vector make_vector(size_t a, T b) { return vector(a, b); } template auto make_vector(size_t a, Ts... ts) { return vector(a, make_vector(ts...)); } /* 確認ポイント cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる 計算量は変わらないが楽できるシリーズ min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる */ /* comment outed because can cause bugs __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } */ int main(){ int n,q;cin>>n>>q; vector> A(n); vector B(n); for(int i = 0; n > i; i++){ cin>>A[i].first>>A[i].second; B[i] = A[i].first; } B.push_back(-1); A.push_back({-1, 0}); B.push_back(1000000001); A.push_back({1000000001, 0}); sort(A.begin(), A.end()); sort(B.begin(), B.end()); vector rR(A.size(), 0); long long cur = A[0].second; for(int i = 1; A.size() > i; i++){ rR[i] = rR[i-1] + abs(A[i].first-A[i-1].first)*cur; cur += A[i].second; } reverse(A.begin(), A.end()); vector rL(A.size(), 0); cur = A[0].second; for(int i = 1; A.size() > i; i++){ rL[i] = rL[i-1] + abs(A[i].first-A[i-1].first)*cur; cur += A[i].second; } reverse(rL.begin(), rL.end()); reverse(A.begin(), A.end()); //for(int i = 0; A.size() > i; i++){ // cout << rR[i] << " "; //} //cout << endl; //for(int i = 0; A.size() > i; i++){ // cout << rL[i] << " "; //} //cout << endl; for(int i = 0; q > i; i++){ long long x;cin>>x; auto z = lower_bound(B.begin(), B.end(), x) - B.begin(); long long ans = (rR[z]-rR[z-1])/(B[z]-B[z-1])*(x-B[z-1]) + rR[z-1] + (rL[z-1]-rL[z])/(B[z]-B[z-1])*(B[z]-x) + rL[z]; cout << ans << endl; } return 0; }