//Marek Kochanowski #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef short int si; int main() { cout.sync_with_stdio(0); ios_base::sync_with_stdio(0); int N, a, k = 0; cin >> N; vector <int> q; for(int i = 0; i < N; i++) { cin >> a; if(a%2 == 0) k += a; else q.push_back(a); } sort(q.begin(), q.end()); ll res = 0, fres = k; for(int i = q.size()-1; i >= (q.size()%2 == 0 ? 0 : 1); i--) { res += q[i]; //cout << "c: " << q[i] << endl; } fres += res; if(fres == 0) { cout << "NIESTETY"; } else { cout << fres; } 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 | //Marek Kochanowski #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef short int si; int main() { cout.sync_with_stdio(0); ios_base::sync_with_stdio(0); int N, a, k = 0; cin >> N; vector <int> q; for(int i = 0; i < N; i++) { cin >> a; if(a%2 == 0) k += a; else q.push_back(a); } sort(q.begin(), q.end()); ll res = 0, fres = k; for(int i = q.size()-1; i >= (q.size()%2 == 0 ? 0 : 1); i--) { res += q[i]; //cout << "c: " << q[i] << endl; } fres += res; if(fres == 0) { cout << "NIESTETY"; } else { cout << fres; } return 0; } |