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

#define SIZE 1000000

unsigned int org[SIZE + 1];
unsigned long long int t[SIZE + 1];

unsigned int n, m;
unsigned long long int d, h, sum, lastDay;

int main()
{
	scanf("%u %u", &n, &m);
	for (int i=0; i<n; ++i)
	{
		scanf("%u", &org[i]);
	}

	for (int j=0; j<m; ++j)
	{
		scanf("%llu %llu", &d, &h);
		sum = 0;
		for (int i=0; i<n; ++i)
		{
			t[i] += org[i] * (d - lastDay);
			if (t[i] > h)
			{
				sum += t[i] - h;
				t[i] = h;
			}
		}
		lastDay = d;
		printf("%llu\n", sum);
	}
	return 0;
}