CF1003D Coins and Queries 求助!
  • 板块灌水区
  • 楼主zch0707
  • 当前回复1
  • 已保存回复1
  • 发布时间2021/11/8 22:05
  • 上次更新2023/11/4 01:04:04
查看原帖
CF1003D Coins and Queries 求助!
378959
zch0707楼主2021/11/8 22:05

这不对么?

#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:05
加载中...