#include <iostream> #include <algorithm> using namespace std; inline int kie(int n, int * a, int smallest) { if(n == 1 && a[0]%2 == 1) return 0; int sum = 0; for(int i=0; i<n; i++) sum += a[i]; if(sum%2==0) return sum; return sum-smallest; } int main() { int N; int * a; cin >> N; a = new int[N]; int temp = 0; for(int i=0; i<N; i++) { cin >> a[i]; if(a[i]%2==1) { if(a[i]<temp) temp = a[i]; else if(temp == 0) temp = a[i]; } } int sol = kie(N, a, temp); if(sol == 0) cout << "NIESTETY" << endl; else cout << sol << endl; delete [] a; 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 39 40 41 42 43 44 45 46 47 48 49 | #include <iostream> #include <algorithm> using namespace std; inline int kie(int n, int * a, int smallest) { if(n == 1 && a[0]%2 == 1) return 0; int sum = 0; for(int i=0; i<n; i++) sum += a[i]; if(sum%2==0) return sum; return sum-smallest; } int main() { int N; int * a; cin >> N; a = new int[N]; int temp = 0; for(int i=0; i<N; i++) { cin >> a[i]; if(a[i]%2==1) { if(a[i]<temp) temp = a[i]; else if(temp == 0) temp = a[i]; } } int sol = kie(N, a, temp); if(sol == 0) cout << "NIESTETY" << endl; else cout << sol << endl; delete [] a; return 0; } |