-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathC.java
More file actions
46 lines (42 loc) · 1.11 KB
/
C.java
File metadata and controls
46 lines (42 loc) · 1.11 KB
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
package Codeforces;
import java.util.Scanner;
public class C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
long number[] = new long[t];
long sum = 0;
long max = Long.MIN_VALUE;
long min = Long.MAX_VALUE;
for (int i = 0; i < t; i++) {
long a = sc.nextLong();
sum = sum + a;
if (a < min) {
min = a;
}
if (a > max) {
max = a;
}
}
int m = sc.nextInt();
for (int i = 0; i < m; i++) {
long x = sc.nextLong();
long y = sc.nextLong();
long sumEqual = sum;
long coins = 0;
if (x < max) {
} else {
coins = x - max;
sum = sum+coins;
}
sum = sum-x;
if (y < sum) {
} else {
long coins2 = y - sum;
coins += coins2;
}
sum = sumEqual;
System.out.println(coins);
}
}
}