https://hack.codingblocks.com/contests/c/471/1556
https://ide.codingblocks.com/#/s/19139
Wrong answer in UNLOCK
Heyy ! Ur code is giving wrong output for this test case
5 2
3 4 5 2 5
Just use map and maintain one extra array which stores the elements of given array in decreasing order and one by one set b[i] to a[i] if they are not equal . Okiee look at this you will understand !!!
https://ide.codingblocks.com/#/s/19331
1 Like
Hey Sanjay, there is just a small mistake in your code i.e. swap can be done only when k>0. So, just put an if check inside the for loop to check if k>0, as shown below (i have corrected this in your code)
for(int i=0;i<n;i++){
if(k>0){
if(v1[i]==v2[i]){
continue;
}
int temp = m[v2[i]];
m[v1[temp]]= i;
m[v1[i]] = temp;
/* pos[v[i]]=temp;
pos[n-i] =i;*/
swap(v1[temp],v1[i]);
}
k--;
}