import java.util.*; public class kie { public static final int MAX_ODD_NUMBER = 1001; public static void main(String[] args) { //input Scanner scan = new Scanner(System.in); int numberOfBills = scan.nextInt(); //summing and finding minimun int sumOfBills = 0; int minimalOddBill = MAX_ODD_NUMBER; for (int i = 0; i < numberOfBills; i++) { int bill = scan.nextInt(); sumOfBills += bill; if (((bill % 2) == 1) & (bill < minimalOddBill)) minimalOddBill = bill; } //check if sum is even int maximalEvenSum = sumOfBills; if ((maximalEvenSum % 2) == 1) maximalEvenSum -= minimalOddBill; if (maximalEvenSum > 0) System.out.println(maximalEvenSum); else 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 | import java.util.*; public class kie { public static final int MAX_ODD_NUMBER = 1001; public static void main(String[] args) { //input Scanner scan = new Scanner(System.in); int numberOfBills = scan.nextInt(); //summing and finding minimun int sumOfBills = 0; int minimalOddBill = MAX_ODD_NUMBER; for (int i = 0; i < numberOfBills; i++) { int bill = scan.nextInt(); sumOfBills += bill; if (((bill % 2) == 1) & (bill < minimalOddBill)) minimalOddBill = bill; } //check if sum is even int maximalEvenSum = sumOfBills; if ((maximalEvenSum % 2) == 1) maximalEvenSum -= minimalOddBill; if (maximalEvenSum > 0) System.out.println(maximalEvenSum); else System.out.println("NIESTETY"); } } |