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
#include <iostream>
#include <string>
#include <math.h>
using namespace std;


int wagatrawy(int* &wys, int daydif,int b, short* wagi)
{
	int wagatrawy = 0;
	for (int i = 0; i < sizeof(wys); i++){
		wagatrawy +=wys[i] + daydif*wagi[i] - b > 0 ? wys[i] + daydif*wagi[i] - b : 0;
		wys[i] =wys[i] + daydif*wagi[i] < b ? wys[i] + daydif*wagi[i] : b;
	}
	return wagatrawy;
}

int main(string args[]){
	int n, m;
	cin >> n;
	cin >> m;

	short* a = new short[n];
	int* wysokosc = new int[n];
	for (int i = 0; i < n; i++){
		cin >> a[i];
		wysokosc[i] = 0;
	}

	int* waga = new int[m];
	int dp = 0;
	int dk;
	int b;
	for (int i = 0; i < m; i++){
		cin >> dk;
		cin >> b;
		waga[i]=wagatrawy(wysokosc, dk - dp, b, a);
			dp = dk;
	}

	for (int i = 0; i < m; i++)
		cout << waga[i] << endl;

	system("PAUSE");

	return 0;
}