We can maximise the number of pies which can be cooled if we greedily place lowest weight pie on lowest possible rack which can support it and this can be efficiently done if we sort the two arrays
you can look at the solution if you want . algorithm : sorting and greedy

I suggest you to use Insertion sort to sort the array, since it is efficient enough with small arrays, just like in this example - and it doesn't use recursion, so memory requirements will be quite low.

Here is my solution (though written in Pascal) - that I'm really proud of :D
Solution