思路应该没问题,莫名其妙RE了。。。
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define eb(x) emplace_back(x)
using namespace std;
const int SIZE=5010;
int n,k;
int b[SIZE];
int tot,ans[SIZE];
int read()
{
int x=1,res=0;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')x=-1;ch=getchar();}
while(isdigit(ch)){res=(res<<3)+(res<<1)+(ch^48);ch=getchar();}
return x*res;
}
signed main()
{
// freopen("xx.in","r",stdin);
// freopen("xx.out","w",stdout);
n=read(),k=read();
for(int i=1;i<=n;i++) b[i]=k;
if(n&1) for(int i=1;i<=k;i++) ans[++tot]=(n+1)/2,b[(n+1)/2]--;
if(n/2)
{
ans[++tot]=n/2;
b[n/2]--;
for(int i=n;i;i--)
{
while(b[i]>0)
{
ans[++tot]=i;
b[i]--;
}
}
// printf("%d\n",n/2);
}
for(int i=1;i<=n*k;i++) printf("%d ",ans[i]);
return 0;
}
/*
1122
1212
1221
2112
2121
2211
*/