Here is the solution:
function twoCitySchedCost(costs)
sort costs by (cost[0] - cost[1]) ascending
total := 0
n := length / 2
for i from 0 to n - 1
total := total + costs[i][0]
for i from n to length - 1
total := total + costs[i][1]
return total
Time: . Space: .
People with the smallest should go to A. That means A is relatively cheaper for them.