1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "cstdio"
#include "algorithm"
using namespace std;
long long n, m, t[200005], d[200005], pref[200005], x, sum, tmp, k;
int main()
{
  scanf ("%lld%lld", &n, &m);
  for (int i = 0; i < n; i++)
  {
    scanf ("%lld", &x);
    t[i] = x - tmp;
    tmp = x;
  }

  sort (t, t + n);
  for (int i = 0; i < n; i++)
  {
    sum += t[i];
    pref[i] = sum;
  }
  for (int i = 0; i < m; i++)
  {
    scanf ("%lld", &x);
    k = lower_bound(t, t + n, x) - t;
    if (t[k] > x) k--;

    if (k < 0) printf ("0\n");
    else printf ("%lld\n", ((k + 1) * x) - pref[k]);
  }

  return 0;
}