import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Scanner; /* 5 2 4 3 3 3 */ public class kie { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int moneyCount = Integer.parseInt(scanner.next()); int sum = 0; List<Integer> moneyList = new ArrayList<Integer>(moneyCount); for (int i = 0; i < moneyCount; i++){ int note = Integer.parseInt(scanner.next()); sum += note; moneyList.add(note); } moneyList.sort(Comparator.<Integer>naturalOrder()); if (sum % 2 == 0) { System.out.println(sum); return; } else{ for (Integer integer : moneyList) { if (integer % 2 != 0 && sum - integer != 0 && (sum - integer) % 2 == 0){ System.out.println(sum - integer); return; } } } System.out.println("NIESTETY"); } }
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.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Scanner; /* 5 2 4 3 3 3 */ public class kie { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int moneyCount = Integer.parseInt(scanner.next()); int sum = 0; List<Integer> moneyList = new ArrayList<Integer>(moneyCount); for (int i = 0; i < moneyCount; i++){ int note = Integer.parseInt(scanner.next()); sum += note; moneyList.add(note); } moneyList.sort(Comparator.<Integer>naturalOrder()); if (sum % 2 == 0) { System.out.println(sum); return; } else{ for (Integer integer : moneyList) { if (integer % 2 != 0 && sum - integer != 0 && (sum - integer) % 2 == 0){ System.out.println(sum - integer); return; } } } System.out.println("NIESTETY"); } } |