Result: Accepted
Time: 6ms
Memory: 1728kB
#include<iostream>
#include<string>
#include<cstdio>
#include<iomanip>
#include<cctype>
#include<cmath>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
map<char, string> yz;
map<string, char> hh;
vector<int> b;
bool cmp(int x, int y) {
return x < y;
}
int main() {
int t;
int i, j;
int a;
while(cin >> t) {
int sum = 0;
if(t == 0)
break;
int flag = 0;
for(i = 0; i < t; i++) {
cin >> a;
b.push_back(a);
if(a < 2)
flag = 1;
}
sort(b.begin(), b.end(), cmp);
for(i = 1; i < b.size(); i++) {
sum += b[i];
}
sum += 2;
if(flag == 1)
cout << -1 << endl;
else {
cout << sum << endl;
}
b.clear();
}
return 0;
}