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

int main() {
	long n = 0, m = 0;
	long trawa[500000] = {0}, akt[500000] = {0} ;
	scanf("%li %li", &n, &m);				
	for(int i=0;i<n;i++){
		scanf("%li", &trawa[i]);
	}

	for(int i=0;i<m;i++){
		long long int tmp, height;
		scanf("%lld %lld", &tmp, &height);
		unsigned long long int sum = 0;
		for(int j=0;j<n;j++){
			akt[j] += trawa[j];
			if( akt[j]>=height){
				sum += akt[j]-height;
				akt[j] = height;

			}
		}
		printf("%lld\n", sum);
//dodaj trawę 
//obetnij i oblicz sume	
	}

	return 0;
}