Now
for an ideal gas and
(see here.)
So
The rest of the energy is discarded to the surroundings to ensure no overall decrease in entropy. Of course this is simple enough that we could have done the calculation directly from entropy considerations, taking the surroundings into account explicitly. Compare with this example.