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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main() {
    unsigned int n;
    unsigned int m;
    std::cin>>n;
    std::cin>>m;

    std::vector<unsigned long long> gaps;
    unsigned long long prev = 0;
    for(unsigned int i=0; i<n; i++) {
        unsigned long long next;
        std::cin>>next;
        gaps.push_back(next-prev);
        prev = next;
    }

    for(int i=0; i<m; i++) {
        unsigned long long wynik = 0;
        unsigned long d;
        unsigned long lastlost =0;
        std::cin>>d;
        for(unsigned int j=0; j<n; j++) {
            if(lastlost+d<gaps.at(j))
                lastlost = 0;
            else
                lastlost=lastlost+d-gaps.at(j);
            wynik+=lastlost;
        }
        std::cout<<wynik<<std::endl;
    }
}