how can do more optomize this code
About test case 0
S ND me your code[quote=“Vijay-Gwala-1537851266358174, post:1, topic:53684, full:true”]
how can do more optomize this code
[/quote]
Send me your code. This is an 0(n) solution with unordered map. You just have to swap the position of the highest with current position of the element.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,s;
cin>>n>>s;
vector a(n);
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
{ if(s==0)
break;
int index = max_element(a.begin()+i, a.end())- a.begin();
if(index!=i)
{
swap(a[i],a[index]);
s–;
}
}
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
}
No dude this wont work
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.