#include<bits/stdc++.h> #define int long long #define re register
usingnamespace std;
constint N = 2e5 + 10; int n,q; int arr[N],s[N];
inlineintread(){ int r = 0,w = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9'){ r = (r << 1) + (r << 3) + (c ^ 48); c = getchar(); } return r * w; }
signedmain(){ n = read(); q = read(); for (re int i = 1;i <= n;i++) arr[i] = read(); sort(arr + 1,arr + 1 + n); for (re int i = 1;i <= n;i++) s[i] = s[i - 1] + arr[i]; while (q--){ int x; x = read(); int id1 = lower_bound(arr + 1,arr + 1 + n,x) - arr - 1;//因为有可能有多个值为 x 的元素,所以求出值为 x 的区间的边界 int id2 = upper_bound(arr + 1,arr + 1 + n,x) - arr; if (!id1 || id1 == n){//没查到 printf("%lld\n",abs(s[n] - n * x)); continue; } int pre = abs(id1 * x - s[id1]);//求答案 int nxt = abs((n - id2 + 1) * x - (s[n] - s[id2 - 1])); printf("%lld\n",pre + nxt); } return0; }