There are two heat flows in the system.
There's the heat flow from the high temperature reservoir into the system given by Q_{H}..
.. and there's the heat flow from the system into the low temperature reservoir given by Q_{L}.
Since the total energy of the system remains the same over one cycle, the work must equal the net heat flow:
W=Q_{H}-Q_{L}.
The second law does forbid 100 percent conversion of heat into work, but this just means that W \leq Q_{H}. The heat not converted is Q_{L}.
The second law of thermodynamics says that
change in entropy of the system plus surroundings after one cycle is greater than or equal to zero. Since it is a cycle, the system's entropy also remains constant at the end of the cycle, so the entropy of the surroundings must increase.
Where a general infinitesimal
change in entropy is given by:
dS=\frac{dQ}{T}.
We know that entropy leaves the surroundings through heat flow from the high temperature reservoir into the system...
and entropy enters the surroundings through heat flow from the system into the low temperature reservoir.
Since we may take these reservoirs to be large enough to have constant temperature, the net
change in entropy in the surroundings in one cycle is given by:
\Delta S =\frac{Q_{L}}{T_{L}} - \frac{Q_{H}}{T_{H}} \geq 0.As one extra bit, this means that where the efficiency \epsilon of the cycle is given by the ratio of work gotten out over heat put in:
\epsilon\equiv\frac{W}{Q_{H}},
the second law of thermodynamics (i.e., \Delta S\geq 0) gives a tighter upper limit (than just 100%) to the efficiency of these sorts of heat engines:
\epsilon \leq 1-\frac{T_{L}}{T_{H}}.
This is also known as the Carnot efficiency limit, because it's also the efficiency of an ideal Carnot engine.