Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!

Misha would like to construct a rooted tree with n

vertices, indexed from 1 to n, where the root has index 1. Every other vertex has a parent pi, and i is called a child of vertex pi. Vertex u belongs to the subtree of vertex v iff v is reachable from u while iterating over the parents (u, pu, ppu, ...). Clearly, v belongs to its own subtree, and the number of vertices in the subtree is called the size of the subtree. Misha is only interested in trees where every vertex belongs to the subtree of vertex 1

.

Below there is a tree with 6

vertices. The subtree of vertex 2 contains vertices 2, 3, 4, 5. Hence the size of its subtree is 4

.

The branching coefficient of the tree is defined as the maximum number of children in any vertex. For example, for the tree above the branching coefficient equals 2

. Your task is to construct a tree with n vertices such that the sum of the subtree sizes for all vertices equals s

, and the branching coefficient is minimum possible.

Input

The only input line contains two integers n

and s — the number of vertices in the tree and the desired sum of the subtree sizes (2≤n≤105; 1≤s≤1010

).

Output

If the required tree does not exist, output «No». Otherwise output «Yes» on the first line, and in the next one output integers p2

, p3, ..., pn, where pi denotes the parent of vertex i

.

Examples

Input
3 5
Output
Yes
1 1
Input
4 42
Output
No
Input
6 15
Output
Yes
1 2 3 1 5

Note

Below one can find one of the possible solutions for the first sample case. The sum of subtree sizes equals 3+1+1=5

, and the branching coefficient equals 2

.

Below one can find one of the possible solutions for the third sample case. The sum of subtree sizes equals 6+3+2+1+2+1=15

, and the branching coefficient equals 2

.

题意:给定N,S,让你构造一个大小为N的数,使得每个节点子树大小之和为S,如果存在,请构造一个树,使得儿子最多的点的儿子数量(P)最少。

思路:我们发现对于大小一定的树,越瘦长K越大(一条链,最大为N*(N+1)/2),越矮胖越小(菊花树,最小为N+N-1),那么如果K不在这个范围我们输出-1;如果在,我们一定看i有构造一个满足题意的树。 我们可以二分得到P。然后来构造。 我的构造方式是先构造一条链,此时的sum=N*(N+1)/2;如果sum>S,我们就把最下面的点移到上面的某个位置,知道sum=S。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;ll N,S;
ll fa[maxn],q[maxn],d[maxn],head,tail,sz[maxn],son[maxn];
bool check(ll Mid)
{
ll tN=N,now=,p=,res=;
while(tN){
res+=min(p,tN)*now;
if(res>S) return false;
tN-=min(p,tN);
p*=Mid; now++;
} return true;
}
int main()
{
cin>>N>>S;
ll Mn=N+N-; ll Mx=N*(N+)/;
if(S<Mn||S>Mx) return puts("NO"),;
ll L=,R=N-,Mid,res;
while(L<=R){
Mid=(L+R)/;
if(check(Mid)) res=Mid,R=Mid-;
else L=Mid+;
}
puts("YES");
rep(i,,N) sz[i]=; ll Now=Mx,D=;
for(int i=N;;i--){
if(Now==S) break;
if(sz[D]==sz[D-]*res) D++;
if(Now-S>=i-D){
sz[D]++; sz[i]--;
Now-=(i-D);
}
else {
sz[i]--; sz[i-(Now-S)]++;
Now=S;
}
}
head=tail=; q[head]=; d[]=;
ll p=;
rep(i,,N) {
if(sz[i]==) break;
L=p+; R=p+sz[i];
rep(j,L,R){
while(d[q[head]]!=i-||son[q[head]]==res){
head++;
}
fa[j]=q[head]; son[q[head]]++;
q[++tail]=j; d[j]=i;
}
p=R;
}
rep(i,,N) printf("%lld ",fa[i]);
return ;
}

最新文章

  1. Tomcat绑定IPV4端口
  2. HTLM5第一天的内容
  3. 在树莓派2代B型/3代 上安装Fedora23 - Installing Fedora 23 on Raspberry Pi 2 model B or Raspberry Pi 3
  4. php调用phpqrcode.php生成二维码
  5. Java 中的 static 使用之静态方法
  6. shell十三问:关于${0##*/} 和${0%/*}
  7. 如何让Activiti-Explorer使用sql server数据库
  8. 【转】C/C++中的日期和时间 TIME_T与STRUCT TM转换&mdash;&mdash;2013-08-25 16
  9. NoteExpress格式化复制指定输出样式
  10. 当今最流行的Node.js应用开发框架简介
  11. C#Execl
  12. 一步步学习EF Core(3.EF Core2.0路线图)
  13. ELK重难点总结和整体优化配置
  14. CSScript 使用纪要
  15. [转]Jmeter + Grafana + InfluxDB 性能测试监控
  16. python学习之基础语法
  17. Spring Boot(二十):使用spring-boot-admin对spring-boot服务进行监控
  18. 6月3 Smarty基础读取配置
  19. MySQL执行mysql_install_db初始化
  20. BFC 从了解到放弃

热门文章

  1. Qt_OpenGL_教程
  2. 《剑指offer》第二十七题(二叉树的镜像)
  3. Java设计模式(五)——适配器模式
  4. Codeforces 838A - Binary Blocks(二维前缀和+容斥)
  5. English trip -- VC(情景课)10 C I like to watch TV. 我爱看电视
  6. codeforces 55d//Beautiful numbers// Codeforces Beta Round #51
  7. ASP.NET网页生命周期事件
  8. 使用API更新供应商名称及曾用名
  9. Eclipse偏好设置的导入与导出
  10. SSH 本地端口转发