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;
}