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
73
74
75
76
#include <ctime>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
#include <utility>
#include <queue>
#include <list>
#include <iomanip>
#include <set>

#define PI 3.14159265
#define INF LLONG_MAX

using namespace std;

// gupi brutforce do sprawdzania wynikuw
int n,m;
vector<long long> t,d,res,time_of_end;

void read_input()
{
  cin >> n >> m;
  t.resize(n);
  d.resize(m);
  for (int i = 0; i < n; ++i)
    cin >> t[i];
  for (int i = 0; i < m; ++i)
    cin >> d[i];
  res.resize(m);
  time_of_end.resize(n);
}

void print_output()
{
  for (int i = 0; i < m; ++i)
    std::cout << res[i] << std::endl;
}

void solve()
{
  for (int i = 0; i < m; ++i)
  {
    res[i] = 0;
    long long slack = 0;
    time_of_end[0] = t[0];
    if (t[0] < d[i])
    {
      res[i] += d[i] - t[0];
      slack = d[i] - t[0];
      time_of_end[0] = d[i];
    }
    for (int j = 1; j < n; ++j)
    {
      time_of_end[j] = max(t[j], time_of_end[j-1]+d[i]);
      res[i] += time_of_end[j] - t[j];
    }
  }
}

int main(int argc, const char *argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  read_input();
  solve();
  print_output();
  return 0;
}