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
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 1e6+77;
ll a[N];
ll akt[N];

int main () {
	ios_base::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	ll lastd = 0;
	for(int i=1;i<=n;i++) {
		cin >> a[i];
	}	
	ll d,b;
	for(int i=0;i<m;i++) {
		cin >> d >> b;
		for(int j=1;j<=n;j++) {
			akt[j] += a[j]*(d-lastd);
		}
		lastd = d;
		ll res = 0;
		ll aktr = 0;
		for(int j=1;j<=n;j++) {
			if(akt[j]>=b) {
				aktr = akt[j];
				akt[j] = b;
				res += aktr-b;
			}
		}
		cout << res << "\n";
	}
}