#include<iostream> #include<algorithm> using namespace std; int main(){ int n,np=0,suma=0; cin>>n; int tab[n]; for(int i=0;i<n;i++){ cin>>tab[i]; if(tab[i]%2==1)np++;} sort(tab,tab+n); if(np%2==1)np-=1; for(int i=0;i<n;i++){ if(tab[i]%2==0) suma+=tab[i]; else if(tab[i]%2==1 and np>0){suma+=tab[i]; np--;} } if(suma>0)cout<<suma; else cout<<"NIESTETY"; }
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 | #include<iostream> #include<algorithm> using namespace std; int main(){ int n,np=0,suma=0; cin>>n; int tab[n]; for(int i=0;i<n;i++){ cin>>tab[i]; if(tab[i]%2==1)np++;} sort(tab,tab+n); if(np%2==1)np-=1; for(int i=0;i<n;i++){ if(tab[i]%2==0) suma+=tab[i]; else if(tab[i]%2==1 and np>0){suma+=tab[i]; np--;} } if(suma>0)cout<<suma; else cout<<"NIESTETY"; } |