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
#include<iostream>
#include<cstdio>

using namespace std;

long long n, m, t[500001], x, y;
long long tab[500001], last, ans; 

int main()
{
	ios_base::sync_with_stdio( 0 );
	cin>>n>>m;	
	for( int a = 1; a <= n; a++ )cin>>t[a];
	for( int a = 1; a <= m; a++ )
	{
		cin>>x>>y;
		for( int b = 1; b <= n; b++ )
		{
			tab[b] += ( x - last ) * t[b];
			if( tab[b] > y )ans += tab[b] - y;
			tab[ b ] = min( tab[b], y );
		}
		cout<<ans<<endl;
		ans = 0;
		last = x;
	}
	
	return 0;
}