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

using namespace std;

unsigned long long tab[500000];
unsigned long long tab2[500000];

int main()
{
	ios::sync_with_stdio(false);

	unsigned long long n, m, d, b, tmp;

	cin >> n >> m;
	std::fill(tab2, tab2 + n, 0);

	for (unsigned long long i = 0; i < n; ++i)
	{
		cin >> tab[i];
	}

	unsigned long long lastDay = 0;

	unsigned long long sum;
	while(m--)
	{
		sum = 0;
		cin >> d >> b;

		tmp = d;
		d -= lastDay;
		lastDay = tmp;

		for (unsigned long long i = 0; i < n; i++)
		{
			tab2[i] += d * tab[i];
			if (tab2[i] > b)
			{
				sum += tab2[i] - b;
				tab2[i] = b;
			}
		}

		cout << sum << endl;
	}


	return 0;
}