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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <vector>

using namespace std;

struct mow
{
	long day;
	long mowing_height;	
};

vector<long> kilos_mowed(long n, long m, vector<long> daily_grow, vector<mow> mows)
{
	vector<long> result;
	long current_height[n];
	for(long i=0; i<n; i++)
	{
		current_height[i] = 0;
	}
	long day=0;
	for(long i=0; i<m; i++)
	{
		long one_mowing_result=0;
		long current_day = mows[0].day;
		for(long j=0; j<n; j++)
		{
			current_height[j] += (current_day-day)*daily_grow[j];
		}
		for(long j=0; j<n; j++)
		{
			if(current_height[j]>mows[0].mowing_height)
			{
				one_mowing_result += current_height[j]-mows[0].mowing_height;
				current_height[j] = mows[0].mowing_height;
			}
		}
		result.push_back(one_mowing_result);
		day = current_day;
		mows.erase(mows.begin());
	}
	return result;
}

int main()
{
	long n,m;
	cin >> n >> m;
	vector<long> daily_grow;
	for(long i=0; i<n; i++)
	{
		long x;
		cin >> x;
		daily_grow.push_back(x);
	}	
	vector<mow> mows;
	for(long i=0; i<m; i++)
	{
		mow x;
		cin >> x.day;
		cin >> x.mowing_height;
		mows.push_back(x);
	}
	vector<long> answer = kilos_mowed(n,m, daily_grow, mows);
	for(long i=0; i<m; i++)
	{
		cout << answer[i] << endl;
	}
	return 0;
}