First let’s find si: the number of friends who love food i. For some food i, if si≤wi, we can see that all the friends who love i will have food to eat no matter what order you call them. So we want to call them as late as possible.
The solution is like doing a topological sort or BFS: we start from all the i that si≤wi. When visiting a new vertex u, decrease su by one and then if su≤wu, put u in the queue and put it in the call list. Finally we reverse our call list and that’s the answer.