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
#include<iostream>
#include<cstdio>
using namespace std;

long long a,b,c,wyn,value,buggedvaraiable;
long long tab[((int)(1e6))+1];
long long kek[((int)(1e6))+1];

int main(){
    //freopen("wn1.in" , "r" , stdin);
    //freopen("jpwn1gmd.txt" , "w" , stdout);
    cin>>a>>b;
    for(int i=1;i<=a;i++){
        cin>>tab[i];
    }
    for(int i=0;i<b;i++){
        wyn = 0;
        cin>>c;
        if(kek[c] != 0) { cout<<kek[c]<<endl; }
        else {
            value = c - (tab[1] - tab[0]);
            if(value < 0) {value = 0;}
            buggedvaraiable = tab[1] + value;
            //cout<<tab[1]<<": "<<buggedvaraiable<<" "<<value<<endl;
            wyn+=value;
            for(int j=2;j<=a;j++){
                if(buggedvaraiable > tab[j]) { value = buggedvaraiable - tab[j];}
                value += c - (tab[j] - tab[j-1]);
                if(value < 0) {value = 0;}
                //cout<<tab[j]<<": "<<buggedvaraiable<<" "<<value<<endl;
                buggedvaraiable = tab[j] + (buggedvaraiable - tab[j]) + value;
                wyn+=value;
            }
            kek[c] = wyn;
            cout<<wyn<<endl;
        }
    }
    return 0;
}