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

typedef long long LL;
typedef unsigned long long ULL;
LL tab[500100];
LL taba[500100];
int main()
{
        LL n,m,a,A=0,d,b,d_1=0,b_1=0;
        scanf("%lld%lld",&n,&m);
	for (int i=0;i<n;i++) 
	{
		scanf("%lld",&a);
		tab[i]=0;
		taba[i]=a;
		A+=a;
	}
	for (int i=0;i<m;i++)
	{
		scanf("%lld%lld",&d,&b);
		A=0;
		for (int i=0;i<n;i++)
		{
			A+=std::max(tab[i]+(d-d_1)*taba[i]-b,0LL);
			tab[i]=std::min((tab[i]+(d-d_1)*taba[i]),b);
		}
		printf("%lld\n",A);
		b_1=b;
		d_1=d;
	}
        return 0;
}