#include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); int a, b; long long n = 0, p = 0; int n_l = 0, n_min = 1000; cin >> a; for (int i = 0; i < a; ++i) { cin >> b; if ((b & 1) == 0) { p += b; } else { n += b; ++n_l; if (b < n_min) n_min = b; } } if (n_l <= 1) { if (p == 0) cout << "NIESTETY\n"; else cout << p << "\n"; } else { if ((n_l & 1) == 0) cout << n + p << "\n"; else cout << n + p - n_min << "\n"; } 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 | #include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); int a, b; long long n = 0, p = 0; int n_l = 0, n_min = 1000; cin >> a; for (int i = 0; i < a; ++i) { cin >> b; if ((b & 1) == 0) { p += b; } else { n += b; ++n_l; if (b < n_min) n_min = b; } } if (n_l <= 1) { if (p == 0) cout << "NIESTETY\n"; else cout << p << "\n"; } else { if ((n_l & 1) == 0) cout << n + p << "\n"; else cout << n + p - n_min << "\n"; } return 0; } |