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: 2018212212245
In contest: 1275

#include<stdio.h>
#include<stdlib.h>

int comp(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}
int main()
{
	int n, i, count;
	int a[101];
	while(scanf("%d", &n), n)
	{
		count = 0;
		for (i = 1; i <= n; i++)
		{
			scanf("%d", &a[i]);
		}
		qsort(a + 1, n, sizeof(int), comp);
		for (i = n; i >= 1;  i--)
		{
			if (a[i] < 2)
			{
				printf("-1\n");
				goto aa;
			}
			else 
			{
				if (i == 1)
					count += 2;
				else
				    count += a[i];
			}
		}
		printf("%d\n", count);
		aa:;
	}
	return 0;
}