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
//Pawel Hanusik
#include <cstdio>
#include <cstring>
#include <queue>

#include <algorithm>

using namespace std;

int main()
{
    ///INPUT
    int n, m;
    scanf("%d%d", &n, &m);

    queue<long long> klienci;
    for(int i = 0; i < n; ++i)
    {
        long long tmp;
        scanf("%lld", &tmp);
        klienci.push(tmp);
    }

    int piece[m];
    int ret[m];

    for(int i = 0; i < m; ++i)
    {
        scanf("%d", &piece[i]);
        ret[i] = 0;
    }


    ///ALG
    int c = 0;

    int addToC[m];
    memset(addToC, 0, sizeof(addToC));
    bool addToCChanged[m];
    memset(addToCChanged, false, sizeof(addToCChanged));

    while(!klienci.empty())
    {
        int toWait = -klienci.front() + c;
        for(int i = 0; i < m; ++i){
            const int tmp = toWait + addToC[i] + piece[i];
			if (tmp > 0) {
				ret[i] += tmp;
				addToC[i] = tmp;
			}
			else {
				addToC[i] = 0;
			}
        }
        c = klienci.front();

        klienci.pop();
    }

    for(int i = 0; i < m; ++i)
    {
        printf("%d\n", ret[i]);
    }

    return 0;
}