Result: Accepted
Time: 6ms
Memory: 1092kB
#include <stdio.h>
#include <math.h>
int gcd(int a, int b)
{
return b == 0 ? a : gcd(b, a%b);
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
goto ha;
int i,j,sum=0;
int a[100];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
if(a[i]<2)
{
printf("-1\n");
goto haha;
}
}
//pai xu
for (j=0;j<n-1;j++)
for (i=0;i<n-1-j;i++)
{
if(a[i]< a[i + 1])
{
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
for(i=0;i<n;i++)
{
if(i!=n-1)
{
sum=sum+a[i];
}
else
{
sum=sum+2;
}
}
printf("%d\n",sum);
haha:;
}
ha:;
return 0;
}