-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEqualCandy.java
More file actions
25 lines (25 loc) · 846 Bytes
/
EqualCandy.java
File metadata and controls
25 lines (25 loc) · 846 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
import java.util.Scanner;
public class EqualCandy {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextInt()) {
int t = scanner.nextInt();
while (t-- > 0) {
int n = scanner.nextInt();
int[] a = new int[n];
int minCandies = Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
if (a[i] < minCandies) {
minCandies = a[i];
}
}
long candiesEaten = 0;
for (int i = 0; i < n; i++) {
candiesEaten += (a[i] - minCandies);
}
System.out.println(candiesEaten);
}
}
}
}