If i have 3 same bodies, all have different temperatures. How i can get max temperature for some body? I have 3 identical bodies with temperatures $T_1 < T_2 < T_3$. I have working mass, so I can use the Carnot cycle. For example, with the first two bodies, I can extract work equal to $C(\sqrt T_2 - \sqrt T_1 )^2$, where $C$ is the heat capacity. Using this work, I can heat the third body, but do other ways exist to obtain a higher temperature?
 A: The first law of thermodynamics applied to this problem says that the sum of the 3 temperatures must remain the same. The maximum possible temperature follows from the second law, the entropy will in the best case stay the same (suppose that someone claims that some final state is optimal but this has a larger entropy than the initial state, then you can construct a state with the same entropy as the initial state by increasing the temperature of the hottest object and decreasing the temperature of some other object). This means that the product of the temperatures will stay the same. As long as the temperatures of all the bodies except one are not equal, there is always room to extract work from these bodies and dump the energy to the body with the highest temperature while keeping the entropy the same. So, from the initial state we find $c_1$ and $c_2$:
$$
\begin{split}
c_1 &= T_1 + T_2 + T_3\\
c_2 &= T_1 T_2 T_3
\end{split}
$$
The temperature $T_3'$ of the hottest body in the final state and the temperature $T_1'$ of the two coldest bodies can then be solved from the equations:
$$
\begin{split}
2 T_1'+ T_3' = c_1\\
T_1'^2 T_3' = c_2
\end{split}
$$
This yields a cubic equation for $T_3'$.
A: This problem is solved in Callen, Section 4.1 as follows. Let the final high temperature be $T_h$. The two lower temperature bodies will have the same temperature, say $T_c$, otherwise more reversible work could be extracted with the Carnot engine and then the work inserted back back to warm the hot body. Now energy conservation demands that
 $$T_h+2T_c = T_1+T_2+T_3=T_0 \tag{1}$$, at the same time the total entropy change is
$$\begin{align}\Delta S = C \text{ln}\left(\frac{T_c}{T_1}\right)  C \text{ln}\left(\frac{T_c}{T_2}\right) + C \text{ln}\left(\frac{T_h}{T_3}\right)
 \\ = C \text{ln}\left(\frac{T_c^2T_h}{T_1T_2T_3}\right) \end{align} \tag{2}$$
For this to be positive we must have $\frac{T_c^2T_h}{T_1T_2T_3} \ge 1. \tag{3}$ Now eliminate $T_c$ from $(3)$ using $(1)$ 
$$ \frac{1}{4}(T_0-T_h)^2 T_h \ge T_1T_2T_3. \tag{4}$$
We have to find the largest $T_h$ for which the inequality $(4)$ still holds. This of course leads to finding the solutions of the cubic $$ \frac{1}{4}(T_0-x)^2 x =  T_1T_2T_3. \tag{5}$$ whose largest positive root is the sought $T_h$
