Here at the time of exchange of bags, momentum in the direction of individual motion remains conserved. The situation is shown in figure.
When driver of the first truck carrying potatoes, throws a bag of mass `m_(1)`, in a direction perpendicular to the motion direction, towards the other truck, as shown in the figure. during throw, the bag has a velocity `u` in the direction of motion of the first truck. Similarly, when the second truck driver throws the onion bag conserve momentum for both the trucks independently as first truck carrying potatoes
`Mu-m_(1)u-m_(2)u=(M-m_(1)+m_(2))v_(1)`
On solving, velocity of the first truck after exchange is
`v_(1)=(Mu-m_(1)u-m_(2)u)/(M-m_(1)+m_(2))`
Second truck carrying onions
`Mu-m_(2)u-m_(1)u=(M-m_(2)+m_(1))v_(2)`
on solving velocity of the first truck after exchange is
`v_(2)=(Mu-m_(1)u-m_(2)u)/(M-m_(2)+m_(1))`