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
67
68
69
70
71
72
#include <iostream>

using namespace std;
#define Int long long int
#define MAX_SIZE 200000
#define MAX_OVEN_DP 1000000

#define DEBUG(x)

int main() {
    ios::sync_with_stdio(false);

    DEBUG(cout << "Podaj liczbe klientow: ");
    int nb_clients;
    cin >> nb_clients;

    DEBUG(cout << "Podaj liczbe piekarnikow: ";)
    int nb_ovens;
    cin >> nb_ovens;

    DEBUG(cout << "Podaj czasy:\n";)
    Int delta_time[MAX_SIZE];
    Int val;
    Int val_last;
    cin >> val_last;
    delta_time[0] = val_last;
    for (auto i = 1; i < nb_clients; ++i) {
        cin >> val;
        delta_time[i] = val - val_last;
        val_last = val;
    }

    DEBUG(for (auto i = 0; i < nb_clients; ++i)
              cout << delta_time[i] << "\n";)


    auto *oven_dp = new Int[MAX_OVEN_DP + 1];
    for (auto i = 0; i <= MAX_OVEN_DP; ++i) {
        oven_dp[i] = -10;
    }
    Int wait_time;
    Int oven_time;
    Int delta;
    for (auto i = 0; i < nb_ovens; ++i) {
        wait_time = 0;
        DEBUG(cout << "Podaj szybkosc piekarnika: ";)
        cin >> oven_time;
        if (oven_dp[oven_time] != -10) {
            cout << oven_dp[oven_time] << endl;
            continue;
        }
        delta = oven_time - delta_time[0];
        if (delta > 0) {
            wait_time += delta;
        } else {
            delta = 0;
        }
        for (auto j = 1; j < nb_clients; ++j) {
            delta = oven_time - (delta_time[j] - delta);
            if (delta > 0) {
                wait_time += delta;
            } else {
                delta = 0;
            }
        }
        cout << wait_time << endl;
        oven_dp[oven_time] = wait_time;
    }

    delete[] oven_dp;
    return 0;
}