Here is my code. It’s getting TLE on the test case 3. Can you please tell where I’m going wrong?
using namespace std;
int main() {
// your code goes here
int n,k;
cin>>n>>k;
vector v;
v.reserve(100000);
for(int i=0; i<n; i++){
int no;
cin>>no;
v.push_back(no);
}
int i=0;
while(k > 0){
auto max = max_element(v.begin()+i, v.end());
if(v.begin()+i == max){
i++;
}else{
iter_swap(v.begin()+i, max);
k–;
i++;
}
}
for(auto it = v.begin(); it != v.end(); it++){
cout<<*(it)<<" ";
}
return 0;
}