// yuki 1012 荷物収集 // 2020.3.21 bal4u #include #include #include typedef long long ll; int getchar_unlocked(void); int putchar_unlocked(int c); #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) int in() { // 非負整数の入力 int n = 0; int c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void out(ll n) { // 非負整数の表示(出力) int i; char b[30]; if (!n) pc('0'); else { // if (n < 0) pc('-'), n = -n; i = 0; while (n) b[i++] = n % 10 + '0', n /= 10; while (i--) pc(b[i]); } pc('\n'); } // ソート typedef struct { int x, w; ll sw, sxw; } T; T t[100005]; int N; void Usort(T *a, int n) { int i, k; #define B 8 #define BMSK 255 // (1<<8)-1 int t1[1 << B], t2[1 << B]; T *tmp = malloc(n * sizeof(T)); for (k = 0; k < 4; ++k) { // for 32ビット memset(t1, 0, sizeof(t1)), memset(t2, 0, sizeof(t2)); for (i = 0; i < n; ++i) t1[(a[i].x >> k*B) & BMSK]++; for (i = 0; i < BMSK; ++i) t1[i+1] += t1[i]; i = n; while (i--) tmp[--t1[(a[i].x >> k*B) & BMSK]] = a[i]; k++; for (i = 0; i < n; ++i) t2[(tmp[i].x >> k*B) & BMSK]++; for (i = 0; i < BMSK; ++i) t2[i+1] += t2[i]; i = n; while (i--) a[--t2[(tmp[i].x >> k*B) & BMSK]] = tmp[i]; } free(tmp); #undef B } // バイナリサーチ int bs(int x) { int m, l = 0, r = N+1; while (l < r) { m = (l+r) >> 1; if (t[m].x <= x) l = m + 1; else r = m; } return l-1; } int main() { int i, Q; N = in(), Q = in(); for (i = 1; i <= N; ++i) t[i].x = in(), t[i].w = in(); Usort(t+1, N); for (i = 1; i <= N; ++i) { t[i].sw = t[i-1].sw + t[i].w; t[i].sxw = t[i-1].sxw + (ll)t[i].x * t[i].w; } while (Q--) { int X = in(); i = bs(X); ll ans = (2*t[i].sw - t[N].sw) * X + (t[N].sxw - 2*t[i].sxw); out(ans); } return 0; }