Result: Accepted
Time: 42ms
Memory: 1760kB
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=150;
struct node{
int hp,num;
friend bool operator < (const node a1,const node a2){
if(a1.hp!=a2.hp) return a1.hp<a2.hp;
else return a1.num<a2.num;
}
}a[maxn];
struct rule{
bool operator()(const node &a1,const node &a2){
return a1.hp<a2.hp;
}
};
int main(){
int t;
scanf("%d",&t);
while(t--){
priority_queue<node> q;
int n,h,k;
scanf("%d %d %d",&n,&h,&k);
for(int i=0;i<n;i++){
scanf("%d",&a[i].hp);
a[i].num=i+1;
q.push(a[i]);
}
h-=k;
if(h<=0){
printf("Yes\n");
sort(a,a+n,rule());
for(int i=0;i<n;i++) printf("%d%c",a[i].hp," \n"[i==n-1]);
continue;
}
node m;
m.hp=h;
m.num=10000;
q.push(m);
int hack=k;
while(1){
hack=hack*k%110;
if(hack==0) hack=k;
node now=q.top();
q.pop();
if(hack>=now.hp){
if(now.num==10000){
printf("Yes\n");
sort(a,a+n,rule());
for(int i=0;i<n;i++) printf("%d%c",a[i].hp," \n"[i==n-1]);
}
else printf("No\n%d\n",now.num);
break;
}
else if(now.num!=10000) a[now.num-1].hp-=hack;
now.hp-=hack;
q.push(now);
}
}
}