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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class sia {

	public static void main(String[] args) throws IOException{
		
        BufferedReader inn = new BufferedReader(new                             
        InputStreamReader(System.in));                                          
        String[] line1 = inn.readLine().split(" ");                               
        String[] line2 = inn.readLine().split(" ");                               
        
        long[] grasses = new long[Integer.valueOf(line1[0])];
        
        int daybefore=0;
        int sum[] = new int[Integer.valueOf(line1[1])];
		        
        for(int i=0; i<Integer.valueOf(line1[1]); i++){
        	String[] linen = inn.readLine().split(" ");
        	int howMuchDays = Integer.valueOf(linen[0])-daybefore;
        	
        	for(int j=0; j<grasses.length; j++){
        		grasses[j]+=howMuchDays*Integer.valueOf(line2[j]);
        		sum[i]+=Integer.valueOf(linen[1])<grasses[j]?(grasses[j]-Integer.valueOf(linen[1])):0;
        		grasses[j]=Integer.valueOf(linen[1]);
        	}
    		daybefore=Integer.valueOf(linen[0]);
        }

        for(int summ : sum){
        System.out.println(summ);
		
	}
}
}