#include<bits/stdc++.h> using namespace std; int main () { ios_base::sync_with_stdio(false); int n; cin >> n; int mini = 0; int suma = 0; int ilenp = 0; int x; for(int i=0;i<n;i++) { cin >> x; suma += x; if(x%2==1){ ilenp++; if(mini == 0 or x < mini) { suma += mini; suma -= x; mini = x; } } } int res = suma + (ilenp%2==0) * mini; if(res) cout << res << endl; else cout << "NIESTETY" << endl; }
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 | #include<bits/stdc++.h> using namespace std; int main () { ios_base::sync_with_stdio(false); int n; cin >> n; int mini = 0; int suma = 0; int ilenp = 0; int x; for(int i=0;i<n;i++) { cin >> x; suma += x; if(x%2==1){ ilenp++; if(mini == 0 or x < mini) { suma += mini; suma -= x; mini = x; } } } int res = suma + (ilenp%2==0) * mini; if(res) cout << res << endl; else cout << "NIESTETY" << endl; } |