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
#include <cstdio>
using namespace std;

long long timeOfClients[200001];

int main() {
  int numberOfClients, numberOfOvens;

  scanf("%d%d", &numberOfClients, &numberOfOvens);
  for(int i = 0; i < numberOfClients; ++i)
    scanf("%lld", timeOfClients + i);

  for(int i = 0; i < numberOfOvens; ++i) {
    long long waitingTime = 0;
    int timeOfBaking;
    scanf("%d", &timeOfBaking);
    long long endOfBaking = timeOfBaking;

    for(int j = 0; j < numberOfClients; ++j) {
      if(endOfBaking <= timeOfClients[j])
        endOfBaking = timeOfClients[j] + timeOfBaking;
      else {
        waitingTime += endOfBaking - timeOfClients[j];
        endOfBaking += timeOfBaking;
      }
    }
    printf("%lld\n", waitingTime);
  }
  return 0;
}