Expected output is incorrect


#1

for input:
10
4 3 5 9 2

output is 2 3 5 9 which gives a cost of 30,
but the correct output is 5 2 3 9 which gives a cost of 23


#2

The given array of indices is sorted. So,input should be
10
4 2 3 5 9