#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int main () {
int n;
scanf("%d",&n);
int result = 0;
for ( int i = 0; i < n; i++ ) {
int a;
scanf("%d",&a);
if ( a % 2 == 0 )
result+=a;
else
v.push_back(a);
}
int b = v.size();
sort(v.begin(),v.end());
while ( b > 1 ) {
result+=v[b-1];
result+=v[b-2];
v.pop_back();
v.pop_back();
b = v.size();
}
if ( result == 0 )
puts("NIESTETY");
else
printf("%d\n",result);
}
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 | #include<bits/stdc++.h> using namespace std; vector<int> v; int main () { int n; scanf("%d",&n); int result = 0; for ( int i = 0; i < n; i++ ) { int a; scanf("%d",&a); if ( a % 2 == 0 ) result+=a; else v.push_back(a); } int b = v.size(); sort(v.begin(),v.end()); while ( b > 1 ) { result+=v[b-1]; result+=v[b-2]; v.pop_back(); v.pop_back(); b = v.size(); } if ( result == 0 ) puts("NIESTETY"); else printf("%d\n",result); } |
English