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
#include <iostream>
using namespace std;

struct grass
{
	int daily; 
	long long last; 
};
grass field[500001];

int main()
{

	int n, m;
	cin >> n >> m;
	for(int i=0; i<n; i++)
	{
		int a;
		cin >> a;
		field[i].daily = a;
		field[i].last = 0;
		
	}
	int d,b,dlast = 0;
	for(int j=0; j<m; j++)
	{
		cin >> d >> b;
		long long sum = 0;
		
		for(int i = 0; i < n; i++)
		{
			long long newvalue = field[i].last + ( field[i].daily * (d-dlast) );
			long long add = newvalue - b;
						
			if(add>=0)
			{
				sum += add;
				field[i].last = b;
			}
			else field[i].last = newvalue;
		}
		dlast = d;		
		cout << sum << endl;
	}

	return 0;
	
}