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 <cstdlib>                                                              

using namespace std;

class Ar {
public:
	int growth = 0;
	int length = 0;
};


int n, m;
int days[64];
Ar ars[64];
int main()
{
	do {
		cin >> n;
	} while (n < 1 || n > 500000);
	do {
		cin >> m;
	} while (m < 1 || m > 500000);
	for (int i = 0; i < n; i++)
		do { cin >> ars[i].growth; } while (ars[i].growth < 1 || ars[i].growth > 1000000);
	for (int i = 1; i <= m; i++)
	{
		int day = 0;
		cin >> day;
		cin >> days[day];

	}

	//Output starts here                                                    
	for (int i = 1; i <= m; i++)
	{
		int result = 0;
		for (int j = 0; j < n; j++)
		{
			ars[j].length += ars[j].growth;
			if (ars[j].length > days[i])
			{
				result += ars[j].length - days[i];
				ars[j].length = days[i];
			}
		}
		cout << result << "\n";
	}
	system("pause");
}