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: 7ms
Memory: 1716kB
Author: 2018212212175
In contest: 1275

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
bool cmp(int a, int b)
{
	return a > b;
}
int main()
{
	int n;
	int a[1010];
	while (scanf("%d", &n) != EOF)
	{
		int f = 1;
		if (n == 0) break;
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			if (a[i] < 2)
			{
				f = 0;
			}
		}
		if (f == 0)
		{
			printf("-1\n");
		}
		if (f == 1)
		{
			sort(a + 1, a + n + 1, cmp);
			int ans = 0;
			for (int i = 1; i < n; i++)
			{
				ans += a[i];
			}
			ans = ans + 2;
			printf("%d\n", ans);
		}
	}
	return 0;
}