J -- Worker

Avin meets a rich customer today. He will earn 1 million dollars if he can solve a hard problem. There are n warehouses and m workers. Any worker in the i-th warehouse can handle ai orders per day. The customer wonders whether there exists one worker assignment method satisfying that every warehouse handles the same number of orders every day. Note that each worker should be assigned to exactly one warehouse and no worker is lazy when working.

Input

The first line contains two integers n (1 ≤ n ≤ 1, 000), m (1 ≤ m ≤ 1018). The second line contains n integers. The i-th integer ai (1 ≤ ai ≤ 10) represents one worker in the i-th warehouse can handle ai orders per day.

Output

If there is a feasible assignment method, print “Yes” in the first line. Then, in the second line, print n integers with the i-th integer representing the number of workers assigned to the i-th warehouse.
Otherwise, print “No” in one line. If there are multiple solutions, any solution is accepted.

Sample Input

2 6
1 2
2 5
1 2

Sample Output

Yes
4 2
No

这道题我在做的时候提交了14次,直到第15次的时候才提交正确,一遍一遍的测试样例,一遍一遍去找是哪里的问题,但是最后感觉都已经超级完美了,还是不对,真心要崩溃啦,后来把里面的int 全部换成了long long 才对,即使我现在也不知道为啥要用long long
代码如下:

#include"stdio.h"
#include"string.h"
#include"iostream"
#include"algorithm"
using namespace std;
long long a[11050],b[11050];
long long gcd(int o,int p)
{
	return p==0?o:gcd(p,o%p);
}
long long lcm(int o,int p)
{
	return o/gcd(o,p)*p;
}
int main()
{
	long long n,m;
	while(~scanf("%lld %lld",&n,&m))
	{
		long long sum=1;
		long long sum1=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(long long i=0;i<n;i++)
		{
			scanf("%lld",&a[i]);
			sum = lcm(sum,a[i]);
		}
	    //printf("%d\n",sum); 
		for(long long i=0;i<n;i++)
		{
			b[i]=sum/a[i];
			//printf("%d####\n",b[i]);
			sum1+=b[i];
		}
		//printf("%d$$$\n",sum1);
		if(m%sum1==0)
		{
			printf("Yes\n");
			for(long long i=0;i<n;i++)
			{
				if(i==0)
				{
					printf("%lld",(m/sum1)*b[i]);
				}
				else
				{
					printf(" %lld",(m/sum1)*b[i]);
				}
			} 
		}
		else
		{
			printf("No");
		}
		printf("\n");
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值