#include<iostream> #include<vector> #include<algorithm> using namespace std; int main (){ vector<int> hajs; int il, war, suma=0,bufor; cin>>il; for(int i=0; i<il; ++i){ cin>>war; hajs.push_back(war); suma+=war; } if(suma%2==0){ cout<<suma; }else{ sort(hajs.begin(), hajs.end()); for(int i=0; i<il; ++i){ bufor = suma; bufor-=hajs[i]; if(bufor%2==0 && bufor>0){ cout<<bufor; break; } if(i==il-1){ cout<<"NIESTETY"; } } } 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<vector> #include<algorithm> using namespace std; int main (){ vector<int> hajs; int il, war, suma=0,bufor; cin>>il; for(int i=0; i<il; ++i){ cin>>war; hajs.push_back(war); suma+=war; } if(suma%2==0){ cout<<suma; }else{ sort(hajs.begin(), hajs.end()); for(int i=0; i<il; ++i){ bufor = suma; bufor-=hajs[i]; if(bufor%2==0 && bufor>0){ cout<<bufor; break; } if(i==il-1){ cout<<"NIESTETY"; } } } return 0; } |