There are
2N
people a company is planning to interview. The cost of flying thei
-th person to cityA
iscosts[i][0]
, and the cost of flying thei
-th person to cityB
iscosts[i][1]
.
Return the minimum cost to fly every person to a city such that exactly
N
people arrive in each city.
Note:
1 <= costs.length <= 100
- It is guaranteed that
costs.length
is even.1 <= costs[i][0], costs[i][1] <= 1000
一家公司預計有
2N
個人要來面試。第i
個人要飛到城市A
的費用為costs[i][0]
,而第i
個人要飛到城市b
的費用為costs[i][1]
。
回傳每個城市都剛好有
N
個人時,飛行所需要的最小花費。
注意:
1 <= costs.length <= 100
- 保證
costs.length
是偶數。1 <= costs[i][0], costs[i][1] <= 1000
N
個人要到城市A
、哪N
個人要到城市B
。costs
重新排列,依據[0] - [1]
。
-10, -170, 350, 10
,然後重新排序。A
越省;反之越後面選B
越省。A
、後半選B
,計算總合即可。LeetCode
C++