#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
int N, Q;
cin >> N >> Q;
vector<ll> A(N + 1); // 1-based indexing
vector<ll> prefix_sum(N + 1, 0);
for (int i = 1; i <= N; ++i) {
cin >> A[i];
}
sort(A.begin() + 1, A.end()); // Sort the array
for (int i = 1; i <= N; ++i) {
prefix_sum[i] = prefix_sum[i - 1] + A[i];
}
for (int qi = 0; qi < Q; ++qi) {
ll x;
cin >> x;
ll total_sum = 0;
for (int l = 1; l <= N; ++l) {
// Find the maximum r such that A[l] + A[r] <= x
ll target = x - A[l];
int r = upper_bound(A.begin() + l, A.end(), target) - A.begin() - 1;
if (r < l) continue; // No valid r for this l
ll t = r - l + 1;
ll S = prefix_sum[r] - prefix_sum[l - 1];
total_sum += (S - A[l] * t);
}
cout << total_sum << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKaW50IG1haW4oKSB7CiAgICBpbnQgTiwgUTsKICAgIGNpbiA+PiBOID4+IFE7CiAgICB2ZWN0b3I8bGw+IEEoTiArIDEpOyAvLyAxLWJhc2VkIGluZGV4aW5nCiAgICB2ZWN0b3I8bGw+IHByZWZpeF9zdW0oTiArIDEsIDApOwoKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IE47ICsraSkgewogICAgICAgIGNpbiA+PiBBW2ldOwogICAgfQoKICAgIHNvcnQoQS5iZWdpbigpICsgMSwgQS5lbmQoKSk7IC8vIFNvcnQgdGhlIGFycmF5CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBOOyArK2kpIHsKICAgICAgICBwcmVmaXhfc3VtW2ldID0gcHJlZml4X3N1bVtpIC0gMV0gKyBBW2ldOwogICAgfQoKICAgIGZvciAoaW50IHFpID0gMDsgcWkgPCBROyArK3FpKSB7CiAgICAgICAgbGwgeDsKICAgICAgICBjaW4gPj4geDsKICAgICAgICBsbCB0b3RhbF9zdW0gPSAwOwoKICAgICAgICBmb3IgKGludCBsID0gMTsgbCA8PSBOOyArK2wpIHsKICAgICAgICAgICAgLy8gRmluZCB0aGUgbWF4aW11bSByIHN1Y2ggdGhhdCBBW2xdICsgQVtyXSA8PSB4CiAgICAgICAgICAgIGxsIHRhcmdldCA9IHggLSBBW2xdOwogICAgICAgICAgICBpbnQgciA9IHVwcGVyX2JvdW5kKEEuYmVnaW4oKSArIGwsIEEuZW5kKCksIHRhcmdldCkgLSBBLmJlZ2luKCkgLSAxOwoKICAgICAgICAgICAgaWYgKHIgPCBsKSBjb250aW51ZTsgLy8gTm8gdmFsaWQgciBmb3IgdGhpcyBsCgogICAgICAgICAgICBsbCB0ID0gciAtIGwgKyAxOwogICAgICAgICAgICBsbCBTID0gcHJlZml4X3N1bVtyXSAtIHByZWZpeF9zdW1bbCAtIDFdOwogICAgICAgICAgICB0b3RhbF9zdW0gKz0gKFMgLSBBW2xdICogdCk7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgdG90YWxfc3VtIDw8IGVuZGw7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K