import java.util.Scanner; public class kie { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); scanner.nextLine(); String notes[] = scanner.nextLine().split(" "); int sum = 0; int minOdd = 1001; boolean evenCountOfOdds = true; for (String snote :notes) { int note = Integer.parseInt(snote); sum += note; if (note % 2 != 0) { evenCountOfOdds = !evenCountOfOdds; if (note < minOdd) { minOdd = note; } } } int maxAllowance = evenCountOfOdds ? sum : sum - minOdd; System.out.println((maxAllowance == 0) ? "NIESTETY" : maxAllowance); } }
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 kie { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); scanner.nextLine(); String notes[] = scanner.nextLine().split(" "); int sum = 0; int minOdd = 1001; boolean evenCountOfOdds = true; for (String snote :notes) { int note = Integer.parseInt(snote); sum += note; if (note % 2 != 0) { evenCountOfOdds = !evenCountOfOdds; if (note < minOdd) { minOdd = note; } } } int maxAllowance = evenCountOfOdds ? sum : sum - minOdd; System.out.println((maxAllowance == 0) ? "NIESTETY" : maxAllowance); } } |