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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;

//#define st first
//#define nd second
#define pb push_back
#define mp make_pair
#define klar(v) memset(v, 0, sizeof(v))
#define bust ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define gcd(a, b) __gcd(a, b);
#define debug cout << "chuj" << endl;
#define endl "\n"

typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
const int maxn = 2e5+10;
//
struct three{
    ll st, nd, rd;
};
three mth(ll a, ll b, ll c){return {a, b, c};}

ll pref[maxn], ret[1000010];
list <three> arr;

ll mach(ll i, ll ilosc, ll minus){
    return (i+i*ilosc)*ilosc/2-minus;
}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    vll roz;
    for(int i = 0; i < n; i++){
        ll x;
        scanf("%lld", &x);
        arr.pb(mth(x, 1, 0));
    }
    vi qs, rr;
    for(int i = 0; i < m; i++){
        int x;
        scanf("%d", &x);
        qs.pb(x);
        rr.pb(x);
    }
    qs.pb(0);
    sort(qs.begin(), qs.end());
    arr.pb(mth(-1, 1, 0));
    
    for(int k = 1; k < qs.size(); k++){
        ll i = qs[k];
        ll ac = 0, ans = 0, odejm = 0;
        auto j = arr.begin();
        while(j != arr.end()){
            ac += j->nd*i;
            //            cout << "jestem w " << j->st << " ac = " << ac << endl;
            if(ac > j->st and j->st >= 0){
                ac -= j->nd*i;
                auto h = j;
                j++;
                //                cout << "merz " << h->st << " to " << j->st << endl;
                j->nd += h->nd;
                j->rd += h->st+h->rd;
                //                j->st -= odejm;
                //                cout << j->st << " suma = " << j->rd-odejm*(j->nd-1) << endl;
                arr.erase(h);
            }
            else{
                //                cout << "dodaje przy " << j->st << " " << mach(i, j->nd-1, j->rd-odejm*(j->nd-1)) << endl;
                ans += mach(i, j->nd-1, j->rd-odejm*(j->nd-1));
                if(j->st != -1)
                    odejm = j->st;
                //                cout <<
                ac = j->st;
                j++;
            }
        }
        ret[i] = ans;
    }
    for(auto i: rr)printf("%lld\n", ret[i]);
}