-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxDandelions.java
More file actions
34 lines (30 loc) · 967 Bytes
/
MaxDandelions.java
File metadata and controls
34 lines (30 loc) · 967 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
33
34
import java.util.*;
public class MaxDandelions {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt(); // number of test cases
while (t-- > 0) {
int n = sc.nextInt();
long[] a = new long[n];
long sum = 0;
long minOdd = Long.MAX_VALUE;
int oddCount = 0;
for (int i = 0; i < n; i++) {
a[i] = sc.nextLong();
sum += a[i];
if (a[i] % 2 == 1) {
oddCount++;
minOdd = Math.min(minOdd, a[i]);
}
}
if (oddCount == 0) {
System.out.println(0);
} else if (oddCount % 2 == 1) {
System.out.println(sum);
} else {
System.out.println(sum - minOdd);
}
}
sc.close();
}
}