#include #include #include #include #include #include #include #include #include #include using namespace std; class UnionFindTree{ typedef struct { int parent; int rank; }base_node; vector node; public: UnionFindTree(int n){ node.resize(n); for(int i=0; i node[y].rank){ node[y].parent = x; }else{ node[x].rank++; unite(x,y); } } }; #include int main(){ int n,m; //cin >> n >> m; scanf("%d%d", &n, &m); UnionFindTree uft(n); for(int i=0; i cnt(n, 0); for(int i=0; i unko(n+1, 0); for(int i=0; i ans(n+1, inf); ans[0] =-1; for(int i=0; i<=n; ++i){ for(int k=1; unko[i]>0; k<<=1){ int c = min(unko[i], k); for(int p=n-c * i; p>=0; --p){ if(ans[p] == inf) continue; if(ans[p + c * i] > ans[p] + c){ ans[p+c * i] = ans[p] + c; } } unko[i] -= c; } } for(int i=1; i<=n; i++){ if(ans[i] == inf) ans[i] = -1; printf("%d\n", ans[i]); } return 0; }