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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	stringstream out;
	
	int n, m;
	cin >> n >> m;
	long long* fields = new long long [n];
	long long* speed = new long long [n];
	for (int i = 0; i < n; ++i)
	{
		cin >> speed[i];
		fields[i] = 0;
	}

	long long day, height;
	long long currentDay = 0, temp;
	long long total;
	for (int i = 0; i < m; ++i)
	{
		cin >> day >> height;
		temp = day;
		currentDay = day - currentDay;
		total = 0;
		for (int i = 0; i < n; i++)
		{
			fields[i] += speed[i] * currentDay;
			total += max(0LL, fields[i] - height);
			fields[i] = min(fields[i], height);
		}
		currentDay = temp;
		out << total << endl;
		total = 0;
	}

	cout << out.str();
	return 0;
}