Original title portal
Idea: For water problems, use the next_permutation() method in STL to solve the full arrangement problem
Code reference
#include <bits/stdc++.h>
using namespace std;
int a[10001],n,m;
int main()
{
cin>>n>>m;
for(int i = 0;i < n;i++)
cin>>a[i];
for(int i = 0;i < m;i++)
next_permutation(a,a+n);
for(int i = 0;i < n;i++)
cout<<a[i]<<" ";
return 0;
}