using System; using static System.Console; using System.Linq; using System.Collections.Generic; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.Arm; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, q) = (c[0], c[1]); var map = NArr(n); var x = NList; Array.Sort(map, (l, r) => l[0].CompareTo(r[0])); var qlist = new List<(int id, int x)>(q); for (var i = 0; i < q; ++i) qlist.Add((i, x[i])); qlist.Sort((l, r) => l.x.CompareTo(r.x)); var ans = new long[q]; var lw = 0L; var rw = 0L; var cur = 0; for (var i = 0; i < n; ++i) { if (map[i][0] <= qlist[0].x) { lw += map[i][1]; ++cur; } else rw += map[i][1]; ans[qlist[0].id] += (long)Math.Abs(qlist[0].x - map[i][0]) * map[i][1]; } for (var i = 1; i < q; ++i) { ans[qlist[i].id] = ans[qlist[i - 1].id]; var cw = 0L; while (cur < n && map[cur][0] <= qlist[i].x) { cw += map[cur][1]; ans[qlist[i].id] += (long)(qlist[i].x - map[cur][0] - map[cur][0] + qlist[i - 1].x) * map[cur][1]; ++cur; } rw -= cw; ans[qlist[i].id] += (lw - rw) * (qlist[i].x - qlist[i -1].x); lw += cw; } WriteLine(string.Join("\n", ans)); } }