import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Scanner; public class kie { public static void main(String[] args) throws FileNotFoundException { final InputStream is; if (args.length >= 1) { is = new FileInputStream(args[0]); } else { is = System.in; } Integer result = solve(is); String toPrint = result != null ? result.toString() : "NIESTETY"; System.out.print(toPrint); } public static Integer solve(InputStream is) { Scanner scanner = new Scanner(is); int numberOfNominals = scanner.nextInt(); if (numberOfNominals == 1) { int theOnlyOne = scanner.nextInt(); if (theOnlyOne % 2 == 1) { return null; } else { return theOnlyOne; } } else { int sum = 0; int minOdd = Integer.MAX_VALUE; while (scanner.hasNext()) { int next = scanner.nextInt(); sum += next; if (next % 2 == 1 && minOdd > next) { minOdd = next; } } return sum%2==0 ? sum : sum-minOdd; } } }
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Scanner; public class kie { public static void main(String[] args) throws FileNotFoundException { final InputStream is; if (args.length >= 1) { is = new FileInputStream(args[0]); } else { is = System.in; } Integer result = solve(is); String toPrint = result != null ? result.toString() : "NIESTETY"; System.out.print(toPrint); } public static Integer solve(InputStream is) { Scanner scanner = new Scanner(is); int numberOfNominals = scanner.nextInt(); if (numberOfNominals == 1) { int theOnlyOne = scanner.nextInt(); if (theOnlyOne % 2 == 1) { return null; } else { return theOnlyOne; } } else { int sum = 0; int minOdd = Integer.MAX_VALUE; while (scanner.hasNext()) { int next = scanner.nextInt(); sum += next; if (next % 2 == 1 && minOdd > next) { minOdd = next; } } return sum%2==0 ? sum : sum-minOdd; } } } |