Start: Jul, 03, 2019 08:38:00
2019年度暑期短学期第七天 助教场
End: Jul, 04, 2019 23:00:00
Time elapsed:
Time remaining:

Problem_ID: G
Result: Accepted
Time: 32ms
Memory: 2540kB
Author: 2018212212161
In contest: 1292

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
const int inf=0x3f3f3f3f;

struct node
{
	int id,num;
	bool operator < (const node & t )const
	{
		if(num==t.num)  return id < t.id;
		return num < t.num;
	}
}p[maxn];

bool cmp(const node &a,const node &b)
{
	return a.num<b.num;
}
priority_queue<node>que;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{

		while(!que.empty())
		{
			que.pop();
		}
		int n,h,k;
		scanf("%d %d %d",&n,&h,&k);
		p[n+1].num=h-k;
		int m=k;
		p[n+1].id=n+1;
	//	cout<<n<<h<<k<<endl;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&p[i].num);
			p[i].id=i;
			que.push(p[i]);
		}
		que.push(p[n+1]);
		if(p[n+1].num<=0)
		{
	//		puts("****");
			printf("Yes\n");
			sort(p+1,p+1+n,cmp);
			for(int i=1;i<=n;i++)
			{
				if(i!=1)    printf(" ");
				printf("%d",p[i].num);
			}
			puts("");
			continue;
		}
		int f=0;
		while(1)
		{
	//		puts("****");
			node now=que.top();
	//		cout<<now.id<<" "<<now.num<<endl;
			que.pop();
			m=m*k%110;
	//		cout<<"m "<<m<<endl;
			p[now.id].num-=(m==0?k:m);
			if(p[now.id].num<=0)
			{
				f=now.id;
				break;
			}
			else
			{
				que.push(p[now.id]);
			}
		}
	//	cout<<"n "<<n<<endl;
		if(f==n+1)
		{
			printf("Yes\n");
			sort(p+1,p+1+n,cmp);
			for(int i=1;i<=n;i++)
			{
		//		cout<<"i "<<i<<" n "<<n<<endl;
				if(i!=1)    printf(" ");
				printf("%d",p[i].num);
			}
			puts("");
		}
		else
		{
			printf("No\n");
			printf("%d\n",f);
		}
	}
}