Codeforces Round #624 (Div. 3)
A.
#include < bits/stdc++.h >
#define dbg (x ) cout << #x << " = " << x << endl
#define eps 1e - 8
#define pi acos (- 1.0 )
using namespace std ;
typedef long long LL ;
template < class T > inline void read ( T &res )
{
char c ;T flag = 1 ;
while ((c = getchar ())< ' 0 ' ||c > ' 9 ' ) if (c == ' - ' )flag =- 1 ;res =c - ' 0 ' ;
while ((c = getchar ())>= ' 0 ' &&c <= ' 9 ' )res =res * 10 +c - ' 0 ' ;res *=flag ;
}
namespace _buff {
const size_t BUFF = 1 << 19 ;
char ibuf [ BUFF ], * ib = ibuf , * ie = ibuf ;
char getc () {
if ( ib == ie ) {
ib = ibuf ;
ie = ibuf + fread ( ibuf , 1 , BUFF , stdin );
}
return ib == ie ? - 1 : * ib ++;
}
}
int qread () {
using namespace _buff ;
int ret = 0 ;
bool pos = true;
char c = getc ();
for (; (c < ' 0 ' || c > ' 9 ' ) && c != ' - ' ; c = getc ()) {
assert (~ c );
}
if (c == ' - ' ) {
pos = false;
c = getc ();
}
for (; c >= ' 0 ' && c <= ' 9 ' ; c = getc ()) {
ret = ( ret << 3 ) + ( ret << 1 ) + ( c ^ 48 );
}
return pos ? ret : -ret ;
}
const int maxn = 5e3 + 7 ;
int t , n , d ;
int fa [maxn ], son [maxn ];
int depth [maxn ], sz [maxn ];
int main ()
{
scanf ( " %d " ,&t );
while (t --) {
scanf ( " %d %d " ,& n , & d );
int sum = 0 ;
int ok = 1 ;
for ( int i = 1 ; i <= n ; ++ i ) {
sum += ( i - 1 );
}
//dbg(sum);
memset ( sz , 0 , sizeof( sz ));
memset ( depth , 0 , sizeof( depth ));
memset ( son , 0 , sizeof( son ));
sz [ 1 ] = 1 ;
for ( int i = 1 ; i <= n ; ++ i ) {
depth [ i ] = depth [ i - 1 ] + 1 ;
sz [depth [ i ]]--;
//dbg(sum - n + i);
if ( d <= sum - n - 1 + i ) {
if (sz [depth [ i ] - 1 ]) {
sum -= ( n + 1 - i );
//dbg(sum);
sz [depth [ i ] - 1 ]--;
sz [depth [ i ]]++;
depth [ i ]--;
}
}
sz [depth [ i ] + 1 ] += 2 ;
}
if ( sum != d ) {
puts ( " NO " );
continue ;
}
for ( int i = 2 ; i <= n ; ++ i ) {
fa [ i ] = 0 ;
for ( int j = 1 ; j < i ; ++ j ) {
if (son [ j ] < 2 && depth [ i ] == depth [ j ] + 1 ) {
son [ j ]++;
fa [ i ] = j ;
break ;
}
}
if (!fa [ i ]) {
ok = 0 ;
break ;
}
}
if (! ok ) {
puts ( " NO " );
}
else {
puts ( " YES " );
for ( int i = 2 ; i <= n ; ++ i ) {
if ( i == 2 ) {
printf ( " %d " ,fa [ i ]);
}
else {
printf ( " %d " ,fa [ i ]);
}
}
}
printf ( "\n " );
}
return 0 ;
}