Time Limit: 2000MS | | Memory Limit: 262144K | | 64bit IO Format: %I64d& %I64u |
[Submit] [GoBack] [Status]
Description
Marina loves Sasha. But she keeps wondering whether Sasha lovesher. Of course, the best way to know it is fortune telling. Thereare many ways of telling fortune, but Marina has picked the easiestone. She takes in her hand one or several camomiles and tears offthe petals one by one. After each petal she pronouncesalternatively "Loves" and "Doesn't love", at that Marina alwaysstarts with "Loves". There are n camomilesgrowing in the field, possessing the numbers of petals equalto a1, a2, ... an. Marina wants to pick a bouquetwith the maximal possible total number of petals so that the resultwould still be "Loves". Help her do that; find the maximal numberof petals possible in the bouquet.
Input
The first line contains an integer n (1 ≤ n ≤ 100),which is the number of flowers growing in the field. The secondline contains n integers ai (1 ≤ ai ≤ 100) which represent thenumber of petals on a given i-th camomile.
Output
Print a single number which is the maximal number of petals inthe bouquet, the fortune telling on which would result in "Loves".If there are no such bouquet, print 0 instead. The bouquetmay consist of a single flower.
#include<iostream>
using namespace std;
int main()
{
int n,i,sum,sum1,sum2,min,count;
int a[105];
while(scanf("%d",&n)!=EOF)
{
count=0;
min=INT_MAX;
sum=sum1=sum2=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
for(i=0;i<n;i++)
{
if((a[i])%2==0)
{ sum1+=a[i];continue;}
sum2+=a[i];
count++;
if(min>a[i])
min=a[i];
}
if(count==0) { printf("0\n");continue;}
if(count%2!=0)
printf("%d\n",sum1+sum2);
else
printf("%d\n",sum1+sum2-min);
}
return 0;
}