#include <iostream> #include <limits> inline bool isEven(unsigned num) { return ((num % 2) == 0); } int main(void) { unsigned n = 0; std::cin.sync_with_stdio(false); std::cout.sync_with_stdio(false); std::cin >> n; long long sumEven = 0; long long noEven = 0; long long sumOdd = 0; long long noOdd = 0; long long minOdd = std::numeric_limits<long long>::max(); for (unsigned i = 0; i < n; ++i) { unsigned num = 0; std::cin >> num; if (isEven(num)) { ++noEven; sumEven += num; } else { ++noOdd; sumOdd += num; if (minOdd > num) minOdd = num; } } long long result = 0; if (isEven(noOdd)) result = sumEven + sumOdd; else result = sumEven + sumOdd - minOdd; if (result > 0) std::cout << result << std::endl; else std::cout << "NIESTETY" << std::endl; 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 | #include <iostream> #include <limits> inline bool isEven(unsigned num) { return ((num % 2) == 0); } int main(void) { unsigned n = 0; std::cin.sync_with_stdio(false); std::cout.sync_with_stdio(false); std::cin >> n; long long sumEven = 0; long long noEven = 0; long long sumOdd = 0; long long noOdd = 0; long long minOdd = std::numeric_limits<long long>::max(); for (unsigned i = 0; i < n; ++i) { unsigned num = 0; std::cin >> num; if (isEven(num)) { ++noEven; sumEven += num; } else { ++noOdd; sumOdd += num; if (minOdd > num) minOdd = num; } } long long result = 0; if (isEven(noOdd)) result = sumEven + sumOdd; else result = sumEven + sumOdd - minOdd; if (result > 0) std::cout << result << std::endl; else std::cout << "NIESTETY" << std::endl; return 0; } |