Two City Scheduling
A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the i^th person to city a is aCosti, and the cost of flying the i^th person to city b is bCosti.
Return the minimum cost to fly every person to a city such that exactly n people arrive in each city.
Example 1
Input
costs = [[10,20],[30,200],[400,50],[30,20]]Output
110The first two people go to city A for costs 10 and 30, and the last two people go to city B for costs 50 and 20, for a total minimum cost of 110.
Example 2
Input
costs = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]Output
1859The minimum total cost to send exactly three people to each city is 1859.
Constraints
- 2 * n == costs.length
- 2 <= costs.length <= 100
- costs.length is even.
- 1 <= aCosti, bCosti <= 1000