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: 1096kB
Author: 2018212212101
In contest: 1275

#include <stdio.h>
#include <string.h>
#include <math.h>

void sort(int a[101]){
	int i,j,tmp;
	for(i=0;i<100;++i){
		if(a[i]==0){
			break;
		}
		for(j=0; j<100-i; ++j){
			if(a[j]==0){
				break;
			}
			if(a[j]<a[j+1]){
				tmp=a[j+1];
				a[j+1]=a[j];
				a[j]=tmp;
			}
		}

	}
}

int main(){
	int t,i,sum=0,a[101],flag;
	char wast[1000];
	while(scanf("%d",&t),t!=0){
		getchar();
		flag=0;
		sum=0;
		memset(a,0,sizeof(a));
		for(i=0;i<t;i++){
			scanf("%d",a+i);
			getchar();
			if(a[i]<=1){
				flag=1;
				printf("-1\n");
				if(i<t-1){
					gets(wast);
				}
				break;
			}
		}

		if(!flag){
			sort(a);
			for(i=0;i<101;++i){
				if(a[i+1]!=0){
					sum+=a[i];
				}else{
					break;
				}
			}
			sum+=2;
			printf("%d\n",sum);
		}

	}
	
	return 0;
}