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

#include<stdio.h>
#include<stdlib.h>
int n;
int a[200];
int cmp1(const void *a, const void *b) {
	return (*(int*)b - *(int*)a);
}
int main() {
	while (scanf("%d", &n) != EOF) {
		if (n == 0)break;
		int sum = 0;
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		qsort(a, n, sizeof(int), cmp1);
		for (int i = 0; i < n; i++) {
			if (a[i] < 2) {
				sum = -1;
				break;
			}

			if (i != n - 1) {
				sum += a[i];
			}
			else {
				sum += 2;
			}
		}
		printf("%d\n", sum);
	}
}