Getting wrong output

question -https://codeforces.com/contest/1417/problem/B

my sol-https://ide.codingblocks.com/s/346620

i am failing in second test case, please check my code and tell me why i am failing and what are the flaws in my code and what would me the better approach to solve this problem

You need to print according to the index, array may not be sorted initially.

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.