The worst case for this problem is when two adjacent dishes each have near x/2 dishes where x is the total number of dishes, which has a limit of 10^6. Since in the worst case for each [dish][ingredient] you have to check all [dish+1][ingredient] the complexity is \mathcal{O}(x^2).
However this problem does not have good test cases and I got AC using this approach initially. The difference in our solutions is that you have used map instead of arrays, which are slower. And I think that is probably the reason for TLE.
You mean the correct solution? You can see the editorial, itβs out now. It relies on the fact that you can separate the |a-b| terms because |a-b| = max(a-b, -a+b).