It is actually rather simple.
Lets start with the fixed rate market. A can borrow at 5% while B can borrow at 7%. Simply said, A has a comparative advantage of 2% in the fixed rate market.
In the floating rate market, A borrows at LIBOR + 1% while B borrows at LIBOR + 2.5%. From here, I'm guessing you already know that A has the comparative advantage as well of 1.5%.
Now by this 2 factors, we can automatically assume that A will borrow in the Fixed rate market due to higher comparative advantage while B will borrow from the floating rate market to not lose out so much.
The question you are asked is simply asking what is the total gains both A and B would get if they were to be engaged in a swap. The answer is simply the difference in the credit spread between the two markets, 2% - 1.5% = 0.5%
Note that 0.5% is the TOTAL gains from the swap. If they were to spread the gains equally, it would mean A would enjoy 0.25% cost savings in the floating rate market while B would also enjoy 0.25% cost savings in the fixed rate market using the swap.
The swap can easily be conducted using the following steps:
1) A borrows 10,000,000 from fixed market at 5%
2) B will pay A monthly fixed interest payments of 6.75%
Note that the net effect here is that B essentially pays fixed payment of 0.25% less than he would have without the swap. A gains a total of 1.75% from this cash flow.
3) B borrows 10,000,000 from the floating market at LIBOR + 2.5%
4) A pays B monthly floating interest payments of LIBOR + 2.5%
From this cash flow, B has a net effect of 0 in the floating rate payments. A will then use the 1.75% gains in the previous cash flow to offset the cash flow here, enabling A to pay only LIBOR + 0.75% monthly. A essentially pays 0.25% less than he would have without the swap as well.
The swap thus allows both parties to gain from the credit spread of 0.5% equally.