Worker

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

每个房间需要的工人数目和工人在该房间工作的时间成反比的,按比例分配人数即可。比如第一组样例,第一个房间里面工人工作时间为第二个房间里的1/2,所以第一个房间所需要工人数为第二个房间的二倍。输出NO的情况就是人数无法分配,即所占比例乘以总人数后不是整数。

(这个题开始一直runtime error(integer divide by zero),就是求比例时候,要除以总份数sum。sum初始化为0,但明明求完sum后它不可能为0啊,然后就替换一下就行了,amazing!)

#include<bits/stdc++.h>

using namespace std;
const int maxn = 1e5+10;
long long gcd(long long x,long long y){
	return y == 0?x:gcd(y,x%y);
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}
int main()
{
	long long n,m;
	cin >> n >> m;
	long long  a[maxn];
	for(int i = 0;i < n;i ++)
		cin >> a[i];
	long long lcmm = lcm(a[0],a[1]);	
	for(int i = 2;i < n;i ++){	
		lcmm = lcm(lcmm,a[i]);
	}
	long long sum = 0;
	for(int i = 0;i < n;i ++){
		sum += lcmm/a[i];
	}
	long long t = sum;//防止出现runtime error(integer divide by zero) 
	long long  x = 0, c[maxn];
	for(int i = 0;i < n;i ++){
		c[x ++] = (lcmm/a[i])*m/t;
	}
	int flag = 0;
	for(int i = 0;i < n;i ++){
		if(c[i] * t != (lcmm/a[i])*m) flag = 1;
	}
	if(flag == 1) cout << "No";
	else{
		cout << "Yes" << endl;
		for(int i = 0;i < n;i ++){
			if(i != n-1)
			  cout << (lcmm/a[i])*m/t << " ";
			else cout << (lcmm/a[n-1])*m/t;
		}
	}
	cout << endl;
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值