#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int ile_NP = 0, ile_P = 0, suma_P = 0, suma_NP = 0, min_NP = INT_MAX; for(int i = 0; i < n; ++i) { int x; scanf("%d", &x); if(x % 2 == 0) { ++ile_P; suma_P += x; } else { ++ile_NP; suma_NP += x; min_NP = std::min(min_NP, x); } } if(ile_NP % 2 == 0) printf("%d", suma_P + suma_NP); else { int wyn = suma_NP - min_NP + suma_P; wyn == 0 ? puts("NIESTETY") : printf("%d", wyn); } }
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 | #include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int ile_NP = 0, ile_P = 0, suma_P = 0, suma_NP = 0, min_NP = INT_MAX; for(int i = 0; i < n; ++i) { int x; scanf("%d", &x); if(x % 2 == 0) { ++ile_P; suma_P += x; } else { ++ile_NP; suma_NP += x; min_NP = std::min(min_NP, x); } } if(ile_NP % 2 == 0) printf("%d", suma_P + suma_NP); else { int wyn = suma_NP - min_NP + suma_P; wyn == 0 ? puts("NIESTETY") : printf("%d", wyn); } } |