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
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();

        long[] height = new long[n];
        long[] growth = new long[n];
        long[] day = new long[m];
        long[] cuts = new long[m];

        for (int i = 0; i < growth.length; i++) {
            growth[i] = sc.nextLong();
        }

        for (int i = 0; i < day.length; i++) {
            day[i] = sc.nextLong();
            cuts[i] = sc.nextLong();
        }

        for (int i = 0; i < m; i++) {
            long dayCount = day[i];
            if (i > 0) {
                dayCount -= day[i - 1];
            }

            long kilos = 0;
            for (int j = 0; j < n; j++) {
                height[j] += dayCount * growth[j];
                long cm = height[j] - cuts[i];
                if (cm > 0) {
                    height[j] = cuts[i];
                    kilos += cm;
                }
            }

            System.out.println(kilos);
        }
        
        sc.close();
    }
}