What is the meaning of maximum work in this thermodynamics question? I am having difficulty understanding this problem.
Given question :-
A mass of 0.25 kg of air in a closed system expands from 2 bar, 60°C to 1 bar, 40°C while receiving 1.005 kJ of heat from a reservoir at 100°C. The surrounding atmosphere is at 0.95 bar and 27°C. 


*

*Determine the maximum work. 

*How much of this work would be done on the atmosphere?
(Take R = 287 J/kg K and $c_v$ = 0.712 kJ/kg K)
Given solution :-
$$ Let :- \\
m = 0.25 kg, \\
p_1 = 2bar, T_1 = 60°C,  \\
p_2 = 1 bar, T_2 = 40°C, \\
p = 0.95 bar, \\
Q = 1.005 kJ \\
\text{Initial volume of air } (v_1) = \frac{mRT_1}{p_1} = 0.119 m^3 \\
\text{Final volume of air } (v_2) = \frac{mRT_2}{p_2} = 0.224m^3 \\
\text{Work done on the atmosphere }(W_1) = p(v_2 - v_1) = \boxed{9.975 kJ} \\
\text{Change in internal energy }(dU) = mc_v(T_2 - T_1) = -3.56 kJ \\
\text{Net workdone }(W_2) = Q - dU = 4.565 kJ \\
\text{Maximum workdone}(W) = W_1 + W_2 = \boxed{14.54 kJ} $$
Why are two different works being done here, and what is the meaning of maximum work ? 

Name of the book : A Textbook of Thermal Engineering
Name of the authors : R.S. Khurmi, J.K. Gupta
Name of the publisher: S. Chand
 A: My interpretation is that there is an unknown external force (pressure $P_{ext}$) to balance the pressure acting on the system, the system would otherwise never be at equilibrium. Since $p$ is a constant offset, the situation is equivalent to assuming that the internal pressure of the system is $P_{sys}-p$ and that the system is in equilibrium with $P_{ext}$. The "net" work is then:
$ W_{2} = \int (P_{sys} - p) dV = \int P_{ext} dV$
So we don't need to know about $P_{ext}$ and the total work ( maximum?) work done by the system $\int P_{sys} dV$ is the derived quantity.
A: 
Why are two different works being done here, and what is the meaning
  of maximum work?

As I previously pointed out in one of my earlier answers, the example problem does not make sense. First of all, the work being done by the gas on the atmosphere (9.975 kJ) is greater than the heat added (1.005 kJ) plus the reduction in internal energy (3.56 kJ), in violation of the first law (conservation of energy). Secondly, adding the net work done (4.565 kJ) to the work done on the atmosphere (9.975 kJ) to come up with something called "maximum work" makes no sense. 
I ran this example by a thermo expert friend of mine and he said, "The question makes no sense to me, and the ‘given solution’ makes even less sense”.
That being said, in order to satisfy the first law, either more heat is needed or, as @user8736288 suggested, and unknown external force is doing work on the gas at the same time the gas is doing work on the atmosphere. We can rule out heat coming from the atmosphere since its temperature is less than the gas at all times. The diagram below shows the possibility of an unknown external force doing 5.41 kJ of work on the gas by way of a second piston. 
Although the diagram would satisfy the first law, it should not be necessary to assume the existence of an unknown external force. If that is what the example wanted you to do, it is a very poor example.What's more, even if we do to satisfy the first law it doesn't address the "maximum work" calculated in the solution. There is no logic, that I can think of, for adding those two quantities and calling it "maximum work".
Hope this helps.

A: The gas has received energy (heat from reservoir), has exerted work (expanded) and has changed its internal energy. The work of expanding does not include the work exerted on the change of internal energy, and therefore needs to be calculated separately.
The change in internal energy is correct, but the formula for calculating the work assumes that this work was done under constant pressure (exterior), which is not correct since the gas pressure is larger than the exterior during the whole process. The correct calculation of the work should account for the pressure dependence on the volume:
$W = \int p(V) dV$
which can be deduced from the ideal gas law but requires knowing the rate at which the heat was transferred to the gas. 
In any case, the work of expanding was mainly performed at the expense of the internal energy, and the heat received is a smaller amount.
