fork download
  1. My soln - https://w...content-available-to-author-only...f.com/viewsolution/17946466</p>
  2. My approach</p>
  3. Assume 0- based indexing</p>
  4. i= index of element</p>
  5. (i-k-1>=0||i+k+1<n)==true then we can place i anywhere in array with index j satisfying (j-k-1>=0||j+k+1<n)==true. And if this condition is false then we cannot move i anywhere.</p>
  6. e.g. if we want to swap i with index j.</p>
  7. Also abs(i-j)>k then we can swap them directly.</p>
  8. Assume i<j </p>
  9. if(j+k+1<n == true ) implies i+k+1<n is also true as i<j</p>
  10. then we can swap i with n-1. i.e ai at index n-1, a[n-1] at i, aj at j </p>
  11. Next swap j with n-1. now ai at j, a[n-1] at i, aj at n-1</p>
  12. Next swap j with n-1. now ai at j, aj at i, a[n-1] at n-1</p>
  13. </p>
  14. If above condition is not true but i-k-1>=0 and j-k-1>=0</p>
  15. then we can chose index 0 instead of n-1 and proceed as above to swap i,j</p>
  16. So, Basically for all index i satisfying i-k-1>=0||i+k+1<n can be placed anywhere. And those which does not satisfy this condition cannot move.</p>
  17. So we sort all elements excluding the index which does not satisfy this condition.</p>
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:1: error: unknown type name ‘My’
 My soln - https://www.codechef.com/viewsolution/17946466</p>
 ^~
prog.c:1:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘-’ token
 My soln - https://www.codechef.com/viewsolution/17946466</p>
         ^
stdout
Standard output is empty