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 <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	unsigned long long int n, m, day, cutHeight, currentDay, delta;
	currentDay = 0;
	cin >> n;
	cin >> m;
	
	vector<long long> grow(n);
	vector<long long> field(n);
	vector<long long> harvest(m);
	
	for (unsigned long long int i = 0; i < n; i++) {
		cin >>grow[i];
		field[i] = 0;
	}
	
	for (unsigned long long i = 0; i < m; i++) {
		cin >> day;
		cin >> cutHeight;
		delta = day - currentDay;
		harvest[i] = 0;
		for (unsigned long long j = 0; j < n; j++) {
			field[j] += delta * grow[j];
			if (field[j] - cutHeight > 0) {
				harvest[i] += (field[j] - cutHeight);
				field[j] = cutHeight;
			}
		}
		currentDay = day;
	}
	
	for (unsigned long long k = 0; k < m; k++) {
		if (harvest[k] >= 0) {
			cout << harvest[k] << endl;
		} else {
			cout << 0 << endl;
		}
		
	}
	
	return 0;
}