#include <iostream> #include <algorithm> #include <cstdio> using namespace std; int main() { int n, x, ilen = 0, ilep = 0; int tabn[50000] = {0}, tabp[50000]= {0}; scanf ("%d", &n); for(int i=0; i<n; i++) { scanf ("%d", &x); if(x % 2 == 0) { tabp[ilep] = x; ilep++; } else { tabn[ilen] = x; ilen++; } } sort(tabp, tabp + ilep); sort(tabn, tabn + ilen); long int sum=0; if(ilen % 2 == 0) x = 0; else x = 1; for(int i = x; i<ilen; i++) sum += tabn[i]; for(int i=0; i<ilep; i++) sum += tabp[i]; if(sum == 0) cout << "NIESTETY"; else cout << sum; }
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 | #include <iostream> #include <algorithm> #include <cstdio> using namespace std; int main() { int n, x, ilen = 0, ilep = 0; int tabn[50000] = {0}, tabp[50000]= {0}; scanf ("%d", &n); for(int i=0; i<n; i++) { scanf ("%d", &x); if(x % 2 == 0) { tabp[ilep] = x; ilep++; } else { tabn[ilen] = x; ilen++; } } sort(tabp, tabp + ilep); sort(tabn, tabn + ilen); long int sum=0; if(ilen % 2 == 0) x = 0; else x = 1; for(int i = x; i<ilen; i++) sum += tabn[i]; for(int i=0; i<ilep; i++) sum += tabp[i]; if(sum == 0) cout << "NIESTETY"; else cout << sum; } |