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
/*Kacper Kielak*/
#include <cstdio>

int main()
{
	int fieldSize, days;
	scanf("%d%d", &fieldSize, &days);
	long long growSpeed = 0;
	long long tempGrow;
	for(int i=0; i<fieldSize; i++)
	{
		scanf("%lld", &tempGrow);
		growSpeed += tempGrow;
	}
	
	long long dayNumber, height;
	long long lastDayNumber = 0;
	long long lastHeight = 0;
	long long weight;
	for(int i=0; i<days; i++)
	{
			scanf("%lld%lld", &dayNumber, &height);
			weight = growSpeed*(dayNumber - lastDayNumber) - fieldSize*(height-lastHeight);
			if(weight < 0)
				weight = 0;
				
			printf("%lld\n", weight);
			
			lastDayNumber = dayNumber;
			lastHeight = height;
	}	
	
	return 0;
}