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

public class sia { 
	
  public static void main(String[] args) {
    
		Scanner scan = new Scanner(System.in);
		int numberOfSpecies = scan.nextInt();
    int numberOfCutting = scan.nextInt();
    
    long[] levelOfGrass = new long[numberOfSpecies];
    for (int i = 0; i < numberOfSpecies; i++)
      levelOfGrass[i] = 0;
    
    int[] speedOfGrowth = new int[numberOfSpecies];
    for (int i = 0; i < numberOfSpecies; i++)
      speedOfGrowth[i] = scan.nextInt();
    
    
    
    long dayOfCutting;
    long levelOfCutting;
    long currentDay = 0;
    long[] hayOfDay = new long[numberOfCutting];
    for (int k = 0; k < numberOfCutting; k++)
      hayOfDay[k] = 0;
    
    for (int k = 0; k < numberOfCutting; k++) {
    
      dayOfCutting = scan.nextLong();
      levelOfCutting = scan.nextLong();
      
      for (int i = 0; i < numberOfSpecies; i++) {
        levelOfGrass[i] += (dayOfCutting - currentDay) * (long)speedOfGrowth[i];
        if (levelOfGrass[i] > levelOfCutting) {
          hayOfDay[k] += (levelOfGrass[i] - levelOfCutting);
          levelOfGrass[i] = levelOfCutting;
          //System.out.println(hayOfDay[k]);
        }
      }
      currentDay = dayOfCutting;
    
    }
    
    for (int k = 0; k < numberOfCutting; k++)
      System.out.println(hayOfDay[k]);
  }
}