速求
  • 板块学术版
  • 楼主zch0707
  • 当前回复0
  • 已保存回复0
  • 发布时间2021/11/8 22:10
  • 上次更新2023/11/4 01:04:00
查看原帖
速求
378959
zch0707楼主2021/11/8 22:10

Coins and Queries 求助

#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;
}
2021/11/8 22:10
加载中...