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
#include <cstdio>

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    long long timeBetweenClients[n];
    long long prev;
    long long buff;
    long long owens[m];
    long long results[m];
    scanf("%lld", &(timeBetweenClients[0]));
    prev = timeBetweenClients[0];
    for(int i=1; i<n; ++i) {
        scanf("%lld", &buff);
        timeBetweenClients[i] = buff - prev;
        prev = buff;
    }
   
    //for(int i=0; i<n; ++i) {
     //   printf("%lld ", timeBetweenClients[i]);
    //}
    //printf("\n");
   
    for(int i=0; i<m; ++i) {
        scanf("%lld", &(owens[i]));
    }
    for(int i=0; i<m; ++i) {
        long long totalTime = 0;
        for(int j=0; j<n; ++j) {
            long long timeToWait = owens[i] - timeBetweenClients[j];
            if(timeToWait > 0) {
                totalTime += owens[i] - timeBetweenClients[j];
            }
        }
        results[i] = totalTime;
    }
    for(int i=0; i<m; ++i) {
        printf("%lld\n", results[i]);
    }
    return 0;
}