#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; vector solve(vector a, const vector& ds) { const int m = ds.size(); if (m == 0) return {}; const int n = a.size(); for (int i = n - 1; i >= 0; --i) { a[i] -= a.front(); } vector num(m + 1, 0); vector bit(m + 1, 0); FOR(i, 1, n) { const ll d = a[i] - a[i - 1]; const int l = distance(ds.begin(), lower_bound(ALL(ds), d)); ++num[l]; bit[l] += d; } REP(i, m) num[i + 1] += num[i]; REP(i, m) bit[i + 1] += bit[i]; vector cnst(m, 0); vector inc{0}; FOR(i, 1, n) { if (a[inc.back()] < a[i]) inc.emplace_back(i); } REP(i, m) { while (inc.size() >= 2 && 1LL * ds[i] * (inc.back() - inc.end()[-2]) > a[inc.back()] - a[inc.end()[-2]]) inc.pop_back(); cnst[i] += a[inc.back()] - 1LL * ds[i] * inc.back(); } REP(i, n) a[i] -= a.back(); inc = vector{n - 1}; for (int i = n - 2; i >= 0; --i) { if (a[inc.back()] < a[i]) inc.emplace_back(i); } vector ans(m, 0); REP(i, m) ans[i] = 1LL * num[i] * ds[i] - bit[i] + cnst[i]; return ans; } int main() { int n, q; cin >> n >> q; vector a(n); REP(i, n) cin >> a[i]; vector d(q); REP(i, q) cin >> d[i]; vector neg, pos; for (const int d_i : set(ALL(d))) { if (d_i < 0) { neg.emplace_back(-d_i); } else { pos.emplace_back(d_i); } } reverse(ALL(neg)); const vector ans_pos = solve(a, pos); reverse(ALL(a)); const vector ans_neg = solve(a, neg); REP(i, q) { if (d[i] < 0) { cout << ans_neg[distance(neg.begin(), lower_bound(ALL(neg), -d[i]))] << '\n'; } else { cout << ans_pos[distance(pos.begin(), lower_bound(ALL(pos), d[i]))] << '\n'; } } return 0; }