#include <iostream> #include <climits> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; int nNp = 0; long long sumP = 0, sumNp = 0; long long minNp = LONG_LONG_MAX; int a = 0; for(int i=0; i<n; ++i) { cin >> a; if(a % 2 != 0) { sumNp += a; nNp++; minNp = (minNp > a) ? a : minNp; } else { sumP += a; } } if(nNp == 1 && sumP == 0) cout << "NIESTETY"; else if(nNp % 2 != 0) cout << (sumNp + sumP - minNp); else cout << (sumNp + sumP); 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 | #include <iostream> #include <climits> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; int nNp = 0; long long sumP = 0, sumNp = 0; long long minNp = LONG_LONG_MAX; int a = 0; for(int i=0; i<n; ++i) { cin >> a; if(a % 2 != 0) { sumNp += a; nNp++; minNp = (minNp > a) ? a : minNp; } else { sumP += a; } } if(nNp == 1 && sumP == 0) cout << "NIESTETY"; else if(nNp % 2 != 0) cout << (sumNp + sumP - minNp); else cout << (sumNp + sumP); return 0; } |