#include <iostream> #include <algorithm> using namespace std; int main() { int n, *a, maks = 0, np = 0; long long *s; cin >> n; s = new long long[n+1]; a = new int[n]; s[n] = 0; for(int i = 0; i < n; i++){ cin >> a[i]; if(a[i] & 1) np++; } sort(a, a+n); if(np & 1) np--; for(int i = n-1; i >= 0; i--) { s[i] = s[i+1] + (a[i] & 1 ? (np-- > 0 ? a[i] : 0) : a[i]); if(s[i] > maks && s[i] %2 == 0) maks = s[i]; } if(!maks) cout << "NIESTETY" << endl; else cout << maks << endl; 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 | #include <iostream> #include <algorithm> using namespace std; int main() { int n, *a, maks = 0, np = 0; long long *s; cin >> n; s = new long long[n+1]; a = new int[n]; s[n] = 0; for(int i = 0; i < n; i++){ cin >> a[i]; if(a[i] & 1) np++; } sort(a, a+n); if(np & 1) np--; for(int i = n-1; i >= 0; i--) { s[i] = s[i+1] + (a[i] & 1 ? (np-- > 0 ? a[i] : 0) : a[i]); if(s[i] > maks && s[i] %2 == 0) maks = s[i]; } if(!maks) cout << "NIESTETY" << endl; else cout << maks << endl; return 0; } |