Start: Jun, 27, 2019 08:30:00
2019年度暑期短学期第二天
End: Jun, 27, 2019 11:30:00
Time elapsed:
Time remaining:

Problem_ID: H
Result: Accepted
Time: 6ms
Memory: 1092kB
Author: 2018212212195
In contest: 1275

#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;
}