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
47
48
49
50
51
52
53
#include <stdio.h>

int main() {
	int n, m;
	int *growSpeed;
	int *grassCuttingDay;
	int *grassCuttingHeight;
	int *grassCurrentHeight;
	int* results;
	//WCZYTYWANIE I PRZYSTOSOWYWANIE
	scanf("%d %d", &n, &m);
	growSpeed = new int[n];
	grassCuttingDay = new int[m + 1];
	grassCuttingHeight = new int[m + 1];
	grassCurrentHeight = new int[m + 1];
	grassCuttingDay[0] = 0;
	grassCuttingHeight[0] = 0;
	grassCurrentHeight[0] = 0;
	results = new int[m]();
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &growSpeed[i]);
	}
	for (int i = 1; i <= m; i++)
	{
		scanf("%d %d", &grassCuttingDay[i], &grassCuttingHeight[i]);
	}
	//OBLICZENIA
	for (int p = 0; p < n; p++)
	{
		for (int k = 1; k <= m; k++)
		{
			int lowerK = k - 1;
			int currentHeight = ((grassCuttingDay[k] - grassCuttingDay[lowerK])*growSpeed[p]) + grassCurrentHeight[lowerK];
			if (currentHeight <= grassCuttingHeight[k])
			{
				grassCurrentHeight[k] = currentHeight;
			}
			else
			{
				results[lowerK] += currentHeight - grassCuttingHeight[k];
				grassCurrentHeight[k] = grassCuttingHeight[k];
			}
		}
	}
	//WYNIKI
	for (int k = 0; k < m; k++)
	{
		printf("%d\n", results[k]);
	}

	return 0;
}