Making a Meal

I tried solving this question.
Will anyone please tell me why my first submission is giving WA when I am using a map to perform the same task as in submission 2 which got an AC.

WA Code:- https://www.codechef.com/viewsolution/39711038

AC Code:- https://www.codechef.com/viewsolution/39711040

in the WA you are not reading t (number of testcases).
And don’t forget to manage the case the map is empty