inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
constint MAXN = 5000 + 10;
int n, d; int fa[MAXN], dep[MAXN], nodedep[MAXN]; bool onchain[MAXN];
voidconstrCBT(){ for (int i = 1; i <= n; ++i) { fa[i] = (i >> 1); } dep[1] = 0; for (int i = 2; i <= n; ++i) { dep[i] = dep[fa[i]] + 1; } int u = n; while (u) { onchain[u] = true; nodedep[dep[u]] = u; u = fa[u]; } }
intmain(){ int T = read(); while (T --> 0) { n = read(); d = read(); constrCBT(); int sumdep = 0; for (int i = 1; i <= n; ++i) sumdep += dep[i]; if (sumdep > d) { puts("NO"); cleanup(); continue; } for (int i = n; i >= 1 && sumdep != d; --i) { if (onchain[i]) continue; bool cont = true; while (cont && sumdep != d) { fa[i] = nodedep[dep[i]]; ++dep[i]; ++sumdep; if (!nodedep[dep[i]]) { cont = false; nodedep[dep[i]] = i; } } } if (sumdep == d) { puts("YES"); for (int i = 2; i <= n; ++i) { printf("%d ", fa[i]); } puts(""); } elseputs("NO"); cleanup(); } return0; }