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
#include <stdio.h>
#include <string.h>

//#define DEBUG
#ifdef DEBUG
#define DBG(...) { fprintf(stderr, "==> [%s %d] ", __FILE__, __LINE__); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); }
#else
#define DBG(...)
#endif

static const int MAX = 200000;
// roznice pomiedzy klientami
static long long d[MAX];

int main() {
    int n, m;
    long long pc = 0;

    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i) {
        long long c;
        scanf("%lld", &c);
        d[i] = c - pc;
        pc = c;
    }
    for (int i = 0; i < m; ++i) {
        long long sum = 0;
        long long t, next = 0;
        scanf("%lld", &t);
        for (int j = 0; j < n; ++j) {
            if (d[j] + next < t) {
                long long diff = t - (d[j] + next);
                DBG("[i:%d][j:%d] diff = t:%lld - d:%lld => %lld", i, j, t, d[j], diff);
                sum += diff;
                next = -diff;
            } else {
                next = 0;
            }
        }
        printf("%lld\n", sum);
    }
    return 0;
}