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
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class sia {
    public static void main(String[] args) {
        try {
            BufferedReader br =
                    new BufferedReader(new InputStreamReader(System.in));

            String first = br.readLine();
            String[] split = first.split(" ");
            int n = Integer.parseInt(split[0]);
            int m = Integer.parseInt(split[1]);
            String second = br.readLine();
            String[] numbers = second.split(" ");
            Integer[] a = map(numbers);

            Long[][] db = new Long[m][2];
            for (int i = 0; i < m; i++) {
                String third = br.readLine();
                String[] split1 = third.split(" ");
                db[i][0] = Long.parseLong(split1[0]);
                db[i][1] = Long.parseLong(split1[1]);
            }

            solve(n,m,a,db);
        } catch (IOException io) {
            io.printStackTrace();
        }
    }
    private static int max(Integer[] a){
        int max = Integer.MIN_VALUE;
        for(int b : a){
            max = Math.max(b,max);
        }
        return max;
    }

    private static void solve(int n, int m, Integer[] a, Long[][] db) {
        long[] ch = new long[a.length];
        long day = 0;

        for (int i = 0; i < m; i++) {
            long d = db[i][0];
            long b = db[i][1];
            long dayDiff = d - day;
            long sum = 0;
            for (int j = a.length-1; j >=0;j--) {
                long h = ch[j] + dayDiff * a[j];
                long cut = h - b > 0 ? h - b : 0;
                sum += cut;
                ch[j]= h-cut;
            }

            System.out.println(sum);
            day = d;
        }
    }

    private static Integer[] map(String[] numbers) {

        Integer[] nums = new Integer[numbers.length];
        for (int i = 0; i < numbers.length; i++) {
            nums[i] = Integer.parseInt(numbers[i]);
        }
        return nums;
    }
}

//
//import java.io.BufferedReader;
//        import java.io.IOException;
//import java.io.InputStreamReader;
//import java.util.Arrays;
//
//public class sia {
//    public static void main(String[] args) {
//        try {
//            BufferedReader br =
//                    new BufferedReader(new InputStreamReader(System.in));
//
//            String first = br.readLine();
//            String[] split = first.split(" ");
//            int n = Integer.parseInt(split[0]);
//            int m = Integer.parseInt(split[1]);
//            String second = br.readLine();
//            String[] numbers = second.split(" ");
//            Integer[] a = map(numbers);
//
//            Long[][] db = new Long[m][2];
//            for (int i = 0; i < m; i++) {
//                String third = br.readLine();
//                String[] split1 = third.split(" ");
//                db[i][0] = Long.parseLong(split1[0]);
//                db[i][1] = Long.parseLong(split1[1]);
//            }
//
//                 solve(n,m,a,db);
//        } catch (IOException io) {
//            io.printStackTrace();
//        }
//    }
//    private static int max(Integer[] a){
//        int max = Integer.MIN_VALUE;
//        for(int b : a){
//            max = Math.max(b,max);
//        }
//        return max;
//    }
//
//    private static void solve(int n, int m, Integer[] a, Long[][] db) {
//        long[] ch = new long[a.length];
//        long day = 0;
//        Arrays.sort(a);
////        int max = max(a);
//        long[] sums = new long[a.length+1];
//        sums[a.length-1]=0;
//        for(int i=0;i<a.length;i++){
//            int j = sums.length-i-2;
//            sums[j]=sums[j+1]+a[i];
//        }
//        System.out.println(Arrays.toString(sums));
//        int cm = a[0];
//        for (int i = 0; i < m; i++) {
//            long d = db[i][0];
//            long b = db[i][1];
//            long dayDiff = d - day;
//            long sum = 0;
//
//            cm = Math.min((int)b,cm);
//            long l = i > 0 ? db[i - 1][1] : 0;
//            int index = cm - (int)l;
//            sum = sums[index];
//            cm+=cm;
//            day = d;
//            System.out.println(sum);
//        }
//    }
//
//    private static Integer[] map(String[] numbers) {
//
//        Integer[] nums = new Integer[numbers.length];
//        for (int i = 0; i < numbers.length; i++) {
//            nums[i] = Integer.parseInt(numbers[i]);
//        }
//        return nums;
//    }
//}