Help with SPOJ ORDERS
I am not getting the logic to solve this. Please explain . Problem link- https://www.spoj.com/problems/ORDERS/