Description
给出n中货币的价值,每种货币可以用无限次,问能不能用这些货币配凑出所有正整数,如果可以则输出-1,不可以则输出不能组成的数中的最小值
Input
第一行为货币种类n,第二行n个整数表示这n中货币的价值
Output
如果这n中货币可以组合成所有正整数则输出-1,否则输出其不能组成的数中的最小值
Sample Input
5
1 2 3 4 5
Sample Output
-1
Solution
水题,判断是否有1即可
Code
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int flag=0;
while(n--)
{
int temp;
cin>>temp;
if(temp==1)
flag=1;
}
if(flag)
cout<<"-1"<<endl;
else
cout<<"1"<<endl;
return 0;
}