E. Construct the Binary Tree

                                                          E. Construct the Binary Tree

You are given two integers nn and dd. You need to construct a rooted binary tree consisting of nn vertices with a root at the vertex 11 and the sum of depths of all vertices equals to dd.

A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex vv is the last different from vv vertex on the path from the root to the vertex vv. The depth of the vertex vv is the length of the path from the root to the vertex vv. Children of vertex vv are all vertices for which vv is the parent. The binary tree is such a tree that no vertex has more than 22 children.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

The only line of each test case contains two integers nn and dd (2≤n,d≤50002≤n,d≤5000) — the number of vertices in the tree and the required sum of depths of all vertices.

It is guaranteed that the sum of nn and the sum of dd both does not exceed 50005000 (∑n≤5000,∑d≤5000∑n≤5000,∑d≤5000).

Output

For each test case, print the answer.

If it is impossible to construct such a tree, print "NO" (without quotes) in the first line. Otherwise, print "{YES}" in the first line. Then print n−1n−1 integers p2,p3,…,pnp2,p3,…,pn in the second line, where pipi is the parent of the vertex ii. Note that the sequence of parents you print should describe some binary tree.

Example

input

Copy

3
5 7
10 19
10 18

output

Copy

YES
1 2 1 3 
YES
1 2 3 3 9 9 2 1 6 
NO

Note

Pictures corresponding to the first and the second test cases of the example:

E. Construct the Binary Tree_第1张图片E. Construct the Binary Tree_第2张图片

 

题意:

构造一个二叉树,每个节点的长度为根节点到该节点的距离,满足n个节点使满足有所有节点总长度为d。

分析:

构造二叉树,将最后一个节点选择最优的位置放置。

代码:

#include
using namespace std;
int main()
{
    int i,j,t,n,d,l,r,p,pre;
    int v[54321];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&d);
        for(i=0;i<=n;i++)v[i]=1;
        p=n*(n-1)/2;
        p-=d;
        l=1;
        r=n-1;
        pre=1;
        while(l

 

你可能感兴趣的:(Codeforces,构造题)