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.Scanner;

public class sia {

	public static void main(String... args) {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);

		int[] line1 = convertToIntArray(scanner.nextLine().split(" "));
		long[] grasses = convertToLongArray(scanner.nextLine().split(" "));
		long[] risingValues = grasses.clone();
		long[] cuts = new long[line1[1]];

		for (int i = 0; i < cuts.length; i++) {
			cuts[i] = convertToIntArray(scanner.nextLine().split(" "))[1];
		}

		int fieldSize = line1[0];

		for (int i = 0; i < cuts.length; i++) {
			long sum = 0;
			for (int j = 0; j < fieldSize; j++) {
				long cuttingVal = Math.max(0, grasses[j] - cuts[i]);
				sum = sum + cuttingVal;
				grasses[j] = cuts[i] + risingValues[j];
			}
			System.out.println(sum);
		}

	}

	private static int[] convertToIntArray(String[] stringArr) {
		int[] intArr = new int[stringArr.length];
		for (int i = 0; i < stringArr.length; i++) {
			intArr[i] = Integer.parseInt(stringArr[i]);
		}
		return intArr;
	}

	private static long[] convertToLongArray(String[] stringArr) {
		long[] longArr = new long[stringArr.length];
		for (int i = 0; i < stringArr.length; i++) {
			longArr[i] = Integer.parseInt(stringArr[i]);
		}
		return longArr;
	}

}