-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrainWater.java
More file actions
32 lines (29 loc) · 775 Bytes
/
rainWater.java
File metadata and controls
32 lines (29 loc) · 775 Bytes
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
import java.util.Scanner;
public class rainWater {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t > 0) {
t--;
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
int s;
if (a[0] > a[n - 1]) {
s = a[n - 1];
} else {
s = a[0];
}
int res = 0;
for (int i = 1; i < n - 1; i++) {
if (a[i] < s) {
res = res + (s - a[i]);
}
}
System.out.println(res);
}
sc.close();
}
}