- #include<iostream>
- #include<algorithm>
- using namespace std;
- #define FOR(i,n,m) for(int i=n;i<=m;i++)
- int n,m,a[10010],c,j,k,minn,minx;
- int main()
- {
- cin>>n>>m;
- FOR(i,0,n-1) cin>>a[i];a[n]=99999999;
- FOR(i,1,m)
- {
- j=n-2;while(a[j]>a[j+1]) j--;
- minn=99999999;FOR(k,j+1,n-1)
- if(a[k]>a[j]&&a[k]<minn) minn=a[k],minx=k;
- swap(a[j],a[minx]);sort(a+j+1,a+n);
- ///FOR(ii,0,n-1) cout<<a[ii]<<' ';cout<<endl;
- }
- FOR(i,0,n-2) cout<<a[i]<<' ';cout<<a[n-1];
- return 0;
- }
复制代码 |