Kindly ignore the previous doubt. I’m getting TLE on test case 3. Can you tell me where I’m going wrong? Here is my code:(Assume all the header files are included)
using namespace std;
int main() {
int n,k;
cin>>n>>k;
vector<int> 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;
}