If I consider a heat engine $\mathrm{H}$ and a refrigerator $\mathrm{R}$ such that:
where $Q_1<Q'_1$ and $Q_2<Q'_2$.
Now if we were to connect the engine and the refrigerator in the following way :
We notice that :
(a) $Q_1=W+Q_2$
(b) $Q'_1=W+Q'_2$
(by the conservation of energy)
From some manipulations of these equations, we arrive at :
$$Q'_1-Q_1=Q'_2-Q_2$$
Now if we were to draw a box around the refrigerator and the engine and in turn call it the new refrigerator, we see that :
Where I have defined $Q=Q'_1-Q_1=Q'_2-Q_2$. The resulting refrigerator that we get has the ability to transfer heat from the hot body to the cold body without the help of any external work, which is a violation of the second law of thermodynamics.
(When I asked the above question in other places, the response was that just like perpetual machines, such a configuration, although might seem to work on paper, cannot exist in real life. Is this what the answer should be?)