#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n, a[1000000],wyn=0,lnp=0; int main(){ scanf("%d",&n); for(int i=0;i<n;i++)scanf("%d",&a[i]); //sort(a,a+n); for(int i=n-1;i>=0;i--){ wyn+=a[i]; if(a[i]%2==1)lnp++; } if(lnp%2==1){//for(int i=0;i<n;i++)if(a[i]%2==1){wyn-=a[i];break;} int od=2000; for(int i=0;i<n;i++)if(a[i]%2==1)od=min(od,a[i]); wyn-=od; } if(wyn)printf("%d\n",wyn); else printf("%s\n","NIESTETY"); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n, a[1000000],wyn=0,lnp=0; int main(){ scanf("%d",&n); for(int i=0;i<n;i++)scanf("%d",&a[i]); //sort(a,a+n); for(int i=n-1;i>=0;i--){ wyn+=a[i]; if(a[i]%2==1)lnp++; } if(lnp%2==1){//for(int i=0;i<n;i++)if(a[i]%2==1){wyn-=a[i];break;} int od=2000; for(int i=0;i<n;i++)if(a[i]%2==1)od=min(od,a[i]); wyn-=od; } if(wyn)printf("%d\n",wyn); else printf("%s\n","NIESTETY"); } |