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

using namespace std;
long long tab[500000],a[500000],n,m,d,b,c=2,x,y[500000];













int main()
{cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>a[i];
y[i]=a[i];
}
while(m--)
{cin>>d>>b;x=0;
	while(c<=d)
	{
		for(int i=0;i<n;i++)
		a[i]=a[i]+y[i];
		c++;
	}
	for(int i=0;i<n;i++)
		{
			if(a[i]>b)
			{x=x+a[i]-b;
			a[i]=b;
			}
		}cout<<x<<endl;
	

}
return 0;
}