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
70
71
72
73
#include <iostream>
#include <vector>

using namespace std;

class Field
{
	typedef unsigned long long INT;
	typedef vector<INT>::iterator v_iter;

	INT size;
	INT harvest_count;
	INT last_cut_day = 0;

	vector<INT> growths;
	vector<INT> heights;

public:
	Field()
	{
		cin >> size >> harvest_count;

		growths.resize(size);
		heights.resize(size);

		for (v_iter it = growths.begin(); it != growths.end(); it++)
		{
			cin >> *it;
		}
	}

	void make_harvest()
	{
		INT day;
		INT cut_height;
		INT delta_days;
		INT new_height_prior_cutting;
		INT crop = 0;
		v_iter g_it;
		v_iter h_it;

		cin >> day >> cut_height;

		delta_days = day - last_cut_day;
		last_cut_day = day;

		for (g_it = growths.begin(), h_it = heights.begin();
			g_it != growths.end();
			g_it++, h_it++)
		{
			new_height_prior_cutting = *h_it + (*g_it * delta_days);
			*h_it = min(new_height_prior_cutting, cut_height);
			crop += max(cut_height, new_height_prior_cutting) - cut_height;
		}

		cout << crop << endl;
	}

	void solve()
	{
		for (INT i = 0; i < harvest_count; i++)
		{
			make_harvest();
		}
	}
};

int main(int argc, char** argv)
{
	Field f;
	f.solve();
	return 0;
}