#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector< short > nieparzyste;
unsigned long long sum = 0;
short temp;
for(int i =0; i<n; i++)
{
cin>>temp;
if(temp%2 == 0){
sum+=temp;
}else{
nieparzyste.push_back(temp);
}
}
if(nieparzyste.size() == 1){
cout<<"NIESTETY";
return 0;
}
sort(nieparzyste.rbegin(), nieparzyste.rend());
for(int i = 0; i< nieparzyste.size()-(nieparzyste.size()%2); i++){
sum+=nieparzyste[i];
}
cout<<sum;
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 | #include <iostream> #include <algorithm> #include <vector> #include <math.h> using namespace std; int main() { int n; cin>>n; vector< short > nieparzyste; unsigned long long sum = 0; short temp; for(int i =0; i<n; i++) { cin>>temp; if(temp%2 == 0){ sum+=temp; }else{ nieparzyste.push_back(temp); } } if(nieparzyste.size() == 1){ cout<<"NIESTETY"; return 0; } sort(nieparzyste.rbegin(), nieparzyste.rend()); for(int i = 0; i< nieparzyste.size()-(nieparzyste.size()%2); i++){ sum+=nieparzyste[i]; } cout<<sum; return 0; } |
English