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
import java.util.Scanner;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;


public class sia {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int[] D = new int[n];
		int[] Prev = new int[n];
		int[] PrevDate = new int[n];
		
		for(int i = 0; i < n; i++){
			D[i] = sc.nextInt();
			Prev[i] = 0;
			PrevDate[i] = 0;
		}
		
		
		for(int i = 0; i < m; i++) {
			long sum = 0;
			int d = sc.nextInt();
			int b = sc.nextInt();
			
			for(int j = 0; j < n; j++) {
				int growth = Prev[j] + D[j] * (d - PrevDate[j]);
				int cut = growth - b;
				PrevDate[j] = d;
				if (cut > 0) {
					Prev[j] = b;
					sum += cut;					
				} else {
					Prev[j] = growth;
				}
				
			}
			System.out.println(sum);
		}
		
		
		
	}

}