import java.util.Scanner;
public class kie {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = scanner.nextInt();
int smallest = 1000;
long result = 0;
boolean canAdd = true;
for (int i = 0; i < count; i++) {
int value = scanner.nextInt();
if (value % 2 == 0) {
result += value;
} else if (value <= smallest) {
canAdd = !canAdd;
if (smallest < 1000) {
result += smallest;
}
smallest = value;
}
}
scanner.close();
if (canAdd) {
result += smallest;
}
if(result == 0) {
System.out.println("NIESTETY");
} else {
System.out.println(result);
}
}
}
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 | import java.util.Scanner; public class kie { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int count = scanner.nextInt(); int smallest = 1000; long result = 0; boolean canAdd = true; for (int i = 0; i < count; i++) { int value = scanner.nextInt(); if (value % 2 == 0) { result += value; } else if (value <= smallest) { canAdd = !canAdd; if (smallest < 1000) { result += smallest; } smallest = value; } } scanner.close(); if (canAdd) { result += smallest; } if(result == 0) { System.out.println("NIESTETY"); } else { System.out.println(result); } } } |
English