costs based on this difference in ascending order.totalCost to 0 to keep track of the total minimum cost.n people in the sorted array and add their cost of going to city A to totalCost.n people in the sorted array and add their cost of going to city B to totalCost.totalCost as the answer.