Result: Accepted
Time: 6ms
Memory: 1092kB
#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);
}
}
}