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
#include <stdio.h>

int n;
int m;
int ts[200002];
int d;
int i,j;
int c,p;

int main(){

    scanf("%d %d\n", &n, &m);
    for(i=0; i < n; i++){
      scanf("%d", &ts[i]);
    }

    for(i=0; i < m; i++ ){
      scanf("%d", &d);
      c = 0;
      p = 0;
      for(j=0; j < n; j++ ){
          if( ts[j] >= c+d) {
            c = ts[j];
          }
          else {
            c = c + d;
            p += c - ts[j];
          }
        }
      printf("%d\n", p);
    }

    return 0;
}