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
#include <iostream>

typedef long long lli;

int* ari; //tab incre
lli* arh; //tab height
int n, m;
lli d, pd = 0, cd, b,ms; //day, prev day, current day, b - wysokosc koszenia

void ReadData() {
	int tmp;
	std::cin >> n >> m;

	ari = new int[n]();
	arh = new lli[n]();

	for (int a = 0; a < n; a++) {
		std::cin >> ari[a];
	}
}

void ProcData() {
	ReadData();

	for (int a = 0; a < m; a++){
		std::cin >> d >> b;
		cd = d - pd;
		ms = 0;

		for (int i = 0; i < n; i++){
			arh[i] += cd * ari[i];
			if (arh[i] > b) {
				ms += (arh[i] - b);
				arh[i] = b;
			}
		}
		pd = d;
		std::cout << ms << std::endl;
	}
}

int main() {
	std::ios_base::sync_with_stdio(false);
	ProcData();

	delete[] ari;
	delete[] arh;
	return 0;
}