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

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(){
	int n;
	while(scanf("%d",&n)!=EOF&&n){
		int a[102]={0},i,z=0,count=0,pass;
		for(i=0;i<n;i++){
		   scanf("%d",&a[i]);
		}
		for(i=0;i<n;i++){
		   if(a[i]<2){
			   printf("-1\n");
			   count=1;
		       break;
		   }
		}
		for(pass=1;pass<n-pass;++pass){
			for(i=0;i<n-pass;++i){
				if(a[i]<a[i+1]){
				  a[101]=a[i];
				  a[i]=a[i+1];
				  a[i+1]=a[101];
				}
			}
		}


		if(n==1&&count==0)
			printf("2\n");
		else if(n>1&&count==0){
			for(i=0;i<n-1;i++){
			   z+=a[i];
			}
			printf("%d\n",z+2);
		}

	}
}