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
#include <iostream>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	int n;
	int m;
	int n_i;
	int d_i;
	int b_i;
	unsigned long long int sum;
	unsigned long long int i_day = 1;
	unsigned long long int* a;
	unsigned long long int* b;
	
	cin >> n >> m;
	
	a = new unsigned long long int[n];
	b = new unsigned long long int[n];
	
	for(int i = 0 ; i < n ; i++) {
		cin >> n_i;
		a[i] = n_i;
		b[i] = n_i;
	}
	
	for(int i = 0 ; i < m ; i++) {
		cin >> d_i >> b_i;
		
		i_day = d_i - i_day;
		sum = 0;
		
		for(int i = 0 ; i < n ; i++) {
			b[i] = (i_day * a[i]) + b[i];
			
			if(b[i] > b_i) {
				sum += b[i] - b_i;
				b[i] = b_i;
			}
		}
		
		i_day = d_i;
		cout << sum << endl;
	}
	return 0;
}