import java.util.Scanner; public class kie { public String exec(int[] nums) { int even = 0; int odd = 0; int oddSmallest = Integer.MAX_VALUE; for (int num : nums) { if (num % 2 == 0) { even += num; } else { odd += num; oddSmallest = Math.min(oddSmallest, num); } } int result = even + odd; if (result % 2 == 1) { result -= oddSmallest; } return result > 0 ? result + "\n" : "NIESTETY\n"; } public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); final int n = scanner.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = scanner.nextInt(); } System.out.println(new kie().exec(nums)); } }
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 | import java.util.Scanner; public class kie { public String exec(int[] nums) { int even = 0; int odd = 0; int oddSmallest = Integer.MAX_VALUE; for (int num : nums) { if (num % 2 == 0) { even += num; } else { odd += num; oddSmallest = Math.min(oddSmallest, num); } } int result = even + odd; if (result % 2 == 1) { result -= oddSmallest; } return result > 0 ? result + "\n" : "NIESTETY\n"; } public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); final int n = scanner.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = scanner.nextInt(); } System.out.println(new kie().exec(nums)); } } |