Problem link : http://www.codechef.com/problems/COOLING

Code link : http://www.codechef.com/viewsolution/2946610

What I have done different here, is that after sorting the arrays in ascending order, I have started i and j from the end. (In other words, I have moved in descending order).

pw[] is the pan weight array

mw[] is the max weight array

Initially, i = last element of pw

j = last element of mw

if pw[i] is greater than mw[j], then that pie is scrapped, and move on to the next largest pie weight. (by i–)

if however, pw[i] is less than or equal to mw[j], then we move on to the next largest pie weight and next largest max pie weight. (i-- and j–).

I am unable to figure out why my code is getting a WA, though the given test cases are satisfied.