Check for error in code

ide:https://ide.codingblocks.com/s/632673
algorithm is correct but not able to solve what changes should be done in code to resolve this

just use next_permutation(a,a+N); function
Reference Code