#include<iostream>
#include<stdio.h>
using namespace std;
int banknoty[1001];
int main()
{
long long suma=0;
int np=0;
int n;
cin>>n;
for(int i=1;i<=1000;i++)
banknoty[i]=0;
while(n--)
{
int x;
scanf("%d",&x);
if((x%2)==0)
suma+=x;
else
{
np++;
banknoty[x]++;
}
}
//cout<<suma<<" "<<np<<endl;
if((suma==0)&&((np%2)==1))
cout<<"NIESTETY";
else if(np>0)
{
if((np%2)==1) np--;
int i=999;
while(np>0)
{
// cout<<np<<endl;
suma+=banknoty[i]*i;
if(banknoty[i]>np) suma-=i;
np-=banknoty[i];
i=i-2;
}
cout<<suma;
}
else
cout<<suma;
// system("pause");
}
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 44 45 46 47 | #include<iostream> #include<stdio.h> using namespace std; int banknoty[1001]; int main() { long long suma=0; int np=0; int n; cin>>n; for(int i=1;i<=1000;i++) banknoty[i]=0; while(n--) { int x; scanf("%d",&x); if((x%2)==0) suma+=x; else { np++; banknoty[x]++; } } //cout<<suma<<" "<<np<<endl; if((suma==0)&&((np%2)==1)) cout<<"NIESTETY"; else if(np>0) { if((np%2)==1) np--; int i=999; while(np>0) { // cout<<np<<endl; suma+=banknoty[i]*i; if(banknoty[i]>np) suma-=i; np-=banknoty[i]; i=i-2; } cout<<suma; } else cout<<suma; // system("pause"); } |
English