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

using namespace std;

long long t[200001];

pair<int, int> d[200001];

long long ret[200001];

int main()
{
  int n, m;
  
  
  scanf("%d %d", &n, &m);
  
  long long aryt = (1LL * n * (n + 1)) / 2;
  long long sall = 0;
  
  for (int i = 0; i < n; i++)
  {
    scanf("%lld", t + i);
    sall += t[i];
  }
  
  
  for (int i = 0; i < m; i++)
  {
    scanf("%d", &d[i].first);
    d[i].second = i;
  }
  
  sort(d, d + m);
  
  int mj = -1;
  for (int j = 0; j < m; j++)
  {
    long long s = 0;
    long long last = 0;
    bool ar = true;
    for (int i = 0; i < n; i++)
    {
      if (last + d[j].first <= t[i] )
      {
        ar = false;
        last = t[i];
      }
      else
      {
        last += d[j].first;
      }
      s += last - t[i];
    }
    ret[d[j].second] = s;
    if (ar)
    {
      mj = j + 1;
      break;
    }
  }
  if (mj > -1)
  for (int j = mj; j < m; j++)
  {
    ret[d[j].second] = aryt * d[j].first - sall;
  }

  for (int j = 0; j < m; j++)
  {
    printf("%lld\n", ret[j]);
  }
  
  return 0;
}