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
/*
 * Brut.
 * 
 */

#include <iostream>
#include <algorithm>
#define MAX_A 500001
#define type long long
using namespace std;

int A[MAX_A];
type hA[MAX_A];

int main()
{
	int n,m;
	cin>> n>> m;
	
	for(int i= 0; i< n; i++)
		cin>> A[i];
	
	type b, d, wyn, ostCie;
	ostCie= 0LL;
	while(m--)
	{
		cin>> d>> b;
		wyn= 0LL;
		for(int i= 0; i< n; i++)
		{
			hA[i]+= (d- ostCie)* A[i];
			
			if( hA[i]> b)
			{
				wyn+= hA[i]- b;
				hA[i]= b;
			}	
		}
		ostCie= d;
		cout<< wyn<< endl;
		
	}
	
	
	
}