#include <iostream> int main(void) { int n = 0; int total = 0; int n_odds = 0; short min_odd = 1001; std::cin >> n; for (int i = 0; i < n; ++i) { short a; std::cin >> a; total += a; if ((a % 2) != 0) { ++n_odds; min_odd = std::min<short>(min_odd, a); } } if ((n_odds % 2) != 0) { total -= min_odd; } if (total > 0) { std::cout << total << 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 | #include <iostream> int main(void) { int n = 0; int total = 0; int n_odds = 0; short min_odd = 1001; std::cin >> n; for (int i = 0; i < n; ++i) { short a; std::cin >> a; total += a; if ((a % 2) != 0) { ++n_odds; min_odd = std::min<short>(min_odd, a); } } if ((n_odds % 2) != 0) { total -= min_odd; } if (total > 0) { std::cout << total << std::endl; } else { std::cout << "NIESTETY" << std::endl; } return 0; } |