#include <iostream> const int oo = 2100000000; void init() { std::ios_base::sync_with_stdio(false); } int n, // 1..1 000 000 a[1000002]; // 1 <= a_i <= 1000 void readData() { std::cin >> n; for (int i = 0; i < n; i++) std::cin >> a[i]; } int minimalOdd, // 1..1000 sum; // 1..1 000 000 000 void calculate() { sum = 0; for (int i = 0; i < n; i++) sum += a[i]; minimalOdd = oo; for (int i = 0; i < n; i++) if ((a[i] % 2 == 1) && (a[i] < minimalOdd)) minimalOdd = a[i]; } int main() { init(); readData(); calculate(); if (sum % 2 == 0) std::cout << sum << "\n"; else if (n == 1) std::cout << "NIESTETY\n"; else std::cout << sum - minimalOdd << "\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 44 45 46 | #include <iostream> const int oo = 2100000000; void init() { std::ios_base::sync_with_stdio(false); } int n, // 1..1 000 000 a[1000002]; // 1 <= a_i <= 1000 void readData() { std::cin >> n; for (int i = 0; i < n; i++) std::cin >> a[i]; } int minimalOdd, // 1..1000 sum; // 1..1 000 000 000 void calculate() { sum = 0; for (int i = 0; i < n; i++) sum += a[i]; minimalOdd = oo; for (int i = 0; i < n; i++) if ((a[i] % 2 == 1) && (a[i] < minimalOdd)) minimalOdd = a[i]; } int main() { init(); readData(); calculate(); if (sum % 2 == 0) std::cout << sum << "\n"; else if (n == 1) std::cout << "NIESTETY\n"; else std::cout << sum - minimalOdd << "\n"; } |