Unlock question

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;

}

hello @JaiGaur

pls go to this link -> https://ide.codingblocks.com/
paste ur code
press ctrl + s and then save
a link will be generated in ur search bar share that link with me

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.