-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parking.java
31 lines (24 loc) · 1002 Bytes
/
Parking.java
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
package parking;
public class Parking {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
int cases = Integer.parseInt(input.nextLine());
for (int i = 0; i < cases; i++) {
// Consume stores to visit.
input.nextLine();
// Stores to visit
String[] storesLocStr = input.nextLine().split(" ");
if (storesLocStr.length == 1) {
System.out.println("0");
continue;
}
int[] storesLoc = new int[storesLocStr.length];
for (int x = 0; x < storesLoc.length; x++) {
storesLoc[x] = Integer.parseInt(storesLocStr[x]);
}
java.util.Arrays.sort(storesLoc);
int parking = (storesLoc[0] + storesLoc[storesLoc.length - 1]) / 2;
System.out.println((parking - storesLoc[0]) * 2 + (storesLoc[storesLoc.length - 1] - parking) * 2);
}
}
}