//package kie; import java.util.ArrayList; import java.util.Scanner; public class kie { class Solution { private final ArrayList<Integer> numbers; public Solution(ArrayList<Integer> numbers) { this.numbers = numbers; } public void solve() { int sum = 0; int mini = Integer.MAX_VALUE; for(int number : numbers) { if(number % 2 == 1) { mini = Math.min(mini, number); } sum += number; } if(sum%2 == 1) { if(numbers.size() == 1) { System.out.println("NIESTETY"); } else { System.out.println(sum - mini); } } else { System.out.println(sum); } } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextInt(); ArrayList<Integer> numbers = new ArrayList<>(); for(int i = 0; i < n; ++i) { int a = sc.nextInt(); numbers.add(a); } Solution solution = new kie().new Solution(numbers); solution.solve(); sc.close(); } }
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 | //package kie; import java.util.ArrayList; import java.util.Scanner; public class kie { class Solution { private final ArrayList<Integer> numbers; public Solution(ArrayList<Integer> numbers) { this.numbers = numbers; } public void solve() { int sum = 0; int mini = Integer.MAX_VALUE; for(int number : numbers) { if(number % 2 == 1) { mini = Math.min(mini, number); } sum += number; } if(sum%2 == 1) { if(numbers.size() == 1) { System.out.println("NIESTETY"); } else { System.out.println(sum - mini); } } else { System.out.println(sum); } } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextInt(); ArrayList<Integer> numbers = new ArrayList<>(); for(int i = 0; i < n; ++i) { int a = sc.nextInt(); numbers.add(a); } Solution solution = new kie().new Solution(numbers); solution.solve(); sc.close(); } } |