I am trying to solve this but i am getting WA everytime. I have used the next_permutation as well as the

algorithm but still am getting WA…Help…!!!

link to the question : http://www.spoj.com/problems/JNEXT/

link to my answer : https://ideone.com/uH0ujN