import java.util.ArrayList; import java.util.Scanner; public class kie { static boolean b = true; int n = 0; ArrayList<Integer> p = null; int suma = 0; int minNieparzysta = Integer.MAX_VALUE; private void loadDane(){ Scanner input = new Scanner(System.in); n = input.nextInt(); p = new ArrayList<Integer>(); for(int i=0; i<n; i++){ int x = input.nextInt(); p.add(x); suma += x; if( (x < minNieparzysta) && (x%2==1) ){ minNieparzysta = x; } } input.close(); } private int getWynik(){ if(suma%2==0){ return suma; }else{ if(minNieparzysta==Integer.MAX_VALUE || suma - minNieparzysta <= 0){ return -1; } return suma - minNieparzysta; } } public static void main(String[] args) { kie kie = new kie(); kie.loadDane(); if(!b){ System.out.println("NIESTETY"); }else{ int wynik = kie.getWynik(); if(wynik == -1) System.out.println("NIESTETY"); else System.out.println(wynik); } // return 0; } }
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 | import java.util.ArrayList; import java.util.Scanner; public class kie { static boolean b = true; int n = 0; ArrayList<Integer> p = null; int suma = 0; int minNieparzysta = Integer.MAX_VALUE; private void loadDane(){ Scanner input = new Scanner(System.in); n = input.nextInt(); p = new ArrayList<Integer>(); for(int i=0; i<n; i++){ int x = input.nextInt(); p.add(x); suma += x; if( (x < minNieparzysta) && (x%2==1) ){ minNieparzysta = x; } } input.close(); } private int getWynik(){ if(suma%2==0){ return suma; }else{ if(minNieparzysta==Integer.MAX_VALUE || suma - minNieparzysta <= 0){ return -1; } return suma - minNieparzysta; } } public static void main(String[] args) { kie kie = new kie(); kie.loadDane(); if(!b){ System.out.println("NIESTETY"); }else{ int wynik = kie.getWynik(); if(wynik == -1) System.out.println("NIESTETY"); else System.out.println(wynik); } // return 0; } } |