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

using namespace std;

int main () {
  int n, m;
  vector<long long> klienci;
  vector<int> piekarniki;

  scanf("%d %d", &n, &m);

  //klienci
  for (int i = 0; i < n; ++i) {
    int t;
    scanf ("%d", &t);
    klienci.push_back(t);
  }

  //piekarniki
  for (int i = 0; i < m; ++i) {
    int t;
    scanf ("%d", &t);
    piekarniki.push_back(t);
  }

  vector<int> roznice;
  for (int i = 0; i < klienci.size(); ++i) {
    if (i == 0) {
      roznice.push_back(klienci[0]);
    } else {
      roznice.push_back(klienci[i] - klienci[i-1]);
    }
  }

  for (int i = 0; i < piekarniki.size(); ++i) {
      long long oczekiwanie = 0;
      long long last_zap = 0;
      int d = piekarniki[i];

      for (int j = 0; j < klienci.size(); ++j) {
          long long t = klienci[j];
          if (last_zap + d < t) {
            last_zap = t;
          } else {
            oczekiwanie += last_zap + d - t;
            last_zap += d;
          }
      }

      printf("%lld\n", oczekiwanie);
  }

  return 0;
}