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
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <random>
#include <cstdlib>
#include <ctime>
#include <limits>
#include <unordered_map>
#include <utility>

using namespace std;


int main(){

  int n, m;
  cin >> n >> m;

  vector<int> custs;
  vector<int> times;

  custs.reserve(n);
  times.reserve(m);
  for(int i = 0; i < n; i ++){
    int tmp;

    cin >> tmp;
    custs.push_back(tmp);
  }
  for(int i = 0; i < m; i ++){
    int tmp;

    cin >> tmp;
    times.push_back(tmp);
  }

  for(auto b : times){
    long long totwait = 0;
    long long lastend = 0;
    for(auto a : custs){
      if(lastend + b <= a){
        lastend = a;
      } else {
        totwait += lastend + b - a;
        lastend = lastend + b;
      }

    }
    cout << totwait << endl;
  }

}