The work-energy theorem says that the total work done on the block is equal to the difference of its kinetic energies at points B and A. Then the total work done on the block is
[tex]W_{\rm total} = K_B - K_A = 4.0\,\mathrm J - 5.0\,\mathrm J = -1.0\,\mathrm J[/tex]
Friction acts on the block to oppose its motion, so it does negative work on the block, -4.5 J.
The only other force acting on the block as it moves is the force P. Let [tex]W_P[/tex] be the work done by the force P. Then the total work done on the block is
[tex]W_{\rm total} = W_P + W_{\rm friction} \iff -1.0\,\mathrm J = W_P - 4.5 \,\mathrm J \implies W_P = \boxed{3.5\,\mathrm J}[/tex]