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
import java.util.*;
import java.lang.*;
import java.io.*;

class sia
{
	public static void main (String[] args) throws java.lang.Exception {
		Scanner in = new Scanner(System.in);
		long n = in.nextInt();
		long m = in.nextInt();
		List<Long> list = new ArrayList<Long>();

		for (long i = 0; i < n; i++) {
			long a = in.nextInt();
			list.add(a);
		}
		
		List<List<Long>> map = new ArrayList<List<Long>>();
		for (long i = 0; i < m; i++) {
			long a = in.nextInt();
			long b = in.nextInt();
			List<Long> tmpList = new ArrayList<Long>(Arrays.asList(a, b));
			map.add(tmpList);
		}
		
		List<Long> grassList = new ArrayList<Long>(Arrays.asList(Long.valueOf(0), Long.valueOf(0), Long.valueOf(0), Long.valueOf(0)));
		long previousDay = 0;
		
		for (int i = 0; i < m; i++) {
			long result = 0;
			long day = map.get(i).get(0) - previousDay;
			previousDay = map.get(i).get(0);
			for (int j = 0; j < n; j++) {
				long newItem = grassList.get(j) + day * list.get(j);
				grassList.set(j, newItem);
			}
			for (int j = 0; j < n; j++) {
				long cut = map.get(i).get(1);
				if (cut < grassList.get(j)) {
					result += grassList.get(j) - cut;
					grassList.set(j, cut);
				}
			}
			System.out.println(result);	
		}

		
		 
	}
}