Problem link: https://acm.timus.ru/problem.aspx?space=1&num=1522
In this problem all you have to do is to come up with clever sorting comparator.
This one is fine:
After sorting the answer is just:
I don't understand how to prove all details of this solution, and hence my request.
I started trying to work out different cases. If we knew that in the first group the system of inequalities $$$a_i \lt b_i \lt c_i$$$ would hold, then the time needed to produce toy $$$T_2$$$ after toy $$$T_1$$$, with empty machines, would amount to $$$a_1 + b_1 + c_1 + c_2$$$; if we tried to produce $$$T_1$$$ after $$$T_2$$$, that is reverse the order, the time would equal to $$$a_2 + b_2 + c_1 + c_2$$$. If we were to compare two values we'd understand why we need to compare using $$$a_i + b_i$$$; $$$cost(T_1, T_2) - cost(T_2, T_1) = a_1 + b_1 - a_2 - b_2$$$.
Similarly, if we knew that the second group satisfies $$$a_i \gt b_i \gt c_i$$$, we could get that $$$cost(T_1, T_2) = a_1 + a_2 + b_2 + c_2$$$; and $$$cost(T_1, T_2) - cost(T_2, T_1) = b_2 + c_2 - b_1 - c_1$$$; and that's why the second group is sorted in descending order.