#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; struct S { ll a, b; }; S op(S x, S y) { return S{x.a + y.a, x.b + y.b}; } S e() { return S{0, 0}; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; VI a(n); rep(i, n) cin >> a[i]; VI qs(q); rep(i, q) cin >> qs[i]; auto convex_check = [](P p1, P p2, P p3) { int dx1 = p2.first - p1.first; int dy1 = p2.second - p1.second; int dx2 = p3.first - p2.first; int dy2 = p3.second - p2.second; return ll(dx2) * dy1 >= ll(dx1) * dy2; }; vector

st; rep(i, n) { P p(i, a[i]); while(st.size() >= 2 && !convex_check(st.end()[-2], st.end()[-1], p)) { st.pop_back(); } st.emplace_back(p); } VI b(n - 1); rep(i, n - 1) b[i] = a[i + 1] - a[i]; // d, i, type vector> evs; rep(i, n - 1) { int b = a[i+1] - a[i]; evs.emplace_back(b, i, 0); } rep(i, q) evs.emplace_back(qs[i], i, 1); sort(all(evs)); vector init_vec(n - 1); rep(i, n - 1) init_vec[i] = S{-1, b[i]}; segtree seg_pos(init_vec), seg_neg(n - 1); VL ans(q); int ptr = int(st.size()) - 1; for(auto [d, i, type]: evs) { if (type) { while(ptr) { int dx = st[ptr].first - st[ptr - 1].first; int dy = st[ptr].second - st[ptr - 1].second; // dy/dx >= d if (dy >= ll(d) * dx) break; ptr--; } int p = st[ptr].first; auto [a1, b1] = seg_pos.prod(0, p); auto [a2, b2] = seg_neg.prod(p, n - 1); ans[i] = (a1 - a2) * d + b1 - b2; } else { seg_pos.set(i, S{0, 0}); seg_neg.set(i, S{-1, b[i]}); } } rep(i, q) cout << ans[i] << '\n'; }