Result: Accepted
Time: 71ms
Memory: 1760kB
#include <bits/stdc++.h>
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", (n))
#define pdd(n,m) printf("%d %d\n", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define pds(n) printf("%d ", (n))
#define plds(n) printf("%lld ", n)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ps(str) printf("%s\n",str)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define mst(a,n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef unsigned long long ULL;
typedef long long LL;
const int maxn = 5e5 + 10;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
int t, n, h, k, lef[110];
struct r {
int i, h, c;
bool operator <(const r& a)const {
if (h == a.h && c == a.c)
return i < a.i;
if (h == a.h)
return c < a.c;
return h < a.h;
}
r(int i = 0, int h = 0,int c=0):i(i),h(h),c(c){}
};
priority_queue<r> q;
int qpow(int a, int b, int c) {
int res = 1;
while (b) {
if (b & 1) {
res = res * a % c;
--b;
}
b >>= 1;
a = a * a % c;
}
return res == 0 ? a : res;
}
int main() {
sd(t);
while (t--) {
mst(lef, 0);
sddd(n, h, k);
while (!q.empty())
q.pop();
rep(i, 1, n + 1) {
sd(lef[i]);
q.push(r(i, lef[i], 0));
}
h -= k;
if (h <= 0) {
ps("Yes");
sort(lef + 1, lef + 1 + n);
rep(i, 1, n + 1)
printf("%d%c", lef[i], " \n"[i == n]);
continue;
}
q.push(r(0, h, 1));
int dmg = k * k % 110, cnt = 2;
while (1) {
r temp = q.top();
q.pop();
temp.h -= dmg;
lef[temp.i] -= dmg;
++cnt;
if (temp.h <= 0) {
if (temp.i == 0) {
ps("Yes");
sort(lef + 1, lef + 1 + n);
rep(i, 1, n + 1)
printf("%d%c", lef[i], " \n"[i == n]);
break;
}
else {
ps("No");
pd(temp.i);
break;
}
}
q.push(temp);
dmg = qpow(k, cnt, 110);
}
}
}