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: 5ms
Memory: 1092kB
Author: 2018212212320
In contest: 1275

#include<stdio.h>
#include<stdlib.h>
int comp(const void *p,const void *q){
	return (*(int *)q-*(int *)p);
}
int main(){
	int n,i,x,m;
	int a[502];
	while(scanf("%d",&n)!=EOF){
		m=0;
		if(n==0)
		break;
		for(i=0;i<n;++i){
			scanf("%d",&a[i]);
		}
		for(i=0;i<n;++i){
			qsort(a,n,sizeof(int),comp);
		}
		for(i=0;i<n-1;++i){
			if(a[i]<2){
				m=-1;
				break;
			}
			else
			m+=a[i];
		}
		for(i=n-1;i<n;++i){
			if(a[i]<2){
				m=-1;
				break;
			}
			else
			m+=2;
		}
		printf("%d\n",m);
	}
	return 0;
}