1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
long long n, m, k, t[200006], x[200006];
int main(){
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i ++)
		cin >> x[i];
	for (int i = 0; i < m; i ++){
		cin >> k;
		long long M = 0;
		t[0] = 0;
		for (int j = 1; j <= n; j ++)
			t[j] = max((t[j - 1] + x[j - 1]) - x[j] + k, (long long) 0),
			M += t[j];
		cout << M << "\n";
	}
	return 0;
}