In Queue

There are $N$ students in a queue with ID $1, 2, 3, ..., N$ respectively. Each student has some coins $C_1, C_2, C_3, ...., C_N$. Minimum coins required for buying a meal from the canteen is $M$.


This is a companion discussion topic for the original entry at https://toph.co/p/in-queue