这不对么?
#include <bits/stdc++.h>
using namespace std;
map<long long,bool,greater<long long> > ms;
int main()
{
long long n,m,x,i,y,ans;
cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>x;
ms[x]=1;
}
for(i=1;i<=m;i++)
{
cin>>y;
if(y%(ms.end()->first-1)) cout<<-1<<endl;
else
{
ans=0;
for(map<long long,bool>::iterator it=ms.begin();it!=ms.end();it++)
{
ans+=y/it->first;
y%=it->first;
if(y==0) break;
}
cout<<ans<<endl;
}
}
return 0;
}