#include <iostream> #include <algorithm> #include <vector> #include <limits> using Number = unsigned long; int main() { std::ios_base::sync_with_stdio(false); Number count; std::cin >> count; std::vector<Number> oddCoins; Number sum{0}; for (Number i = 0; i < count; ++ i) { Number coin; std::cin >> coin; if (coin % 2) { oddCoins.push_back(coin); } else { sum += coin; } } if (oddCoins.size() % 2) { auto minimumPosition = std::min_element(oddCoins.begin(), oddCoins.end()); oddCoins.erase(minimumPosition); } sum = std::accumulate(oddCoins.begin(), oddCoins.end(), sum); if (sum) { std::cout << sum << "\n"; } else { std::cout << "NIESTETY\n"; } }
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 | #include <iostream> #include <algorithm> #include <vector> #include <limits> using Number = unsigned long; int main() { std::ios_base::sync_with_stdio(false); Number count; std::cin >> count; std::vector<Number> oddCoins; Number sum{0}; for (Number i = 0; i < count; ++ i) { Number coin; std::cin >> coin; if (coin % 2) { oddCoins.push_back(coin); } else { sum += coin; } } if (oddCoins.size() % 2) { auto minimumPosition = std::min_element(oddCoins.begin(), oddCoins.end()); oddCoins.erase(minimumPosition); } sum = std::accumulate(oddCoins.begin(), oddCoins.end(), sum); if (sum) { std::cout << sum << "\n"; } else { std::cout << "NIESTETY\n"; } } |