提交时间:2024-03-31 08:53:56
运行 ID: 44555
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=10; int a[N]; int b[N]; int n,x; int vis[N]; int check(){ int res=0; for(int i=1;i<=n;i++){ if(b[i]>=a[i]+x){ res++; } } if(2*res>n) return 1; return 0; } void dfs(int cur){ if(cur==n+1){ if(check()) { for(int i=1;i<=n;i++) printf("%d ",b[i]); printf("\n"); return ; } } for(int i=1;i<=n;i++){ if(vis[i]) continue; b[cur]=i; vis[i]=1; dfs(cur+1); vis[i]=0; b[cur]=0; } return ; } int main(void){ scanf("%d%d",&n,&x); for(int i=1;i<=n;i++) scanf("%d",&a[i]); dfs(1); return 0; }