WA in "Ordering the Soldiers" (ORDERS)

Problem : https://www.codechef.com/problems/ORDERS

My solution : https://www.codechef.com/viewsolution/29108984