#4558. 两地调度

两地调度

题目描述

公司计划面试 2n2n 人。给你一个数组 costscosts ,其中 costs[i]=[aCosti,bCosti]costs[i] = [aCost_i, bCost_i] 。第 ii 人飞往 aa 市的费用为 aCostiaCost_i ,飞往 bb 市的费用为 bCostibCost_i

返回将每个人都飞到 aabb 中某座城市的最低费用,要求每个城市都有 nn 人抵达

输入格式

第一行一个整数表示 2n2n

接下来 2n2n 行,每行两个空格隔开的整数表示 aCostiaCost_ibCostibCost_i

输出格式

一行一个整数表示答案。

示例 1:

4
10 20
30 200
400 50
30 20
110

解释:

第一个人去 a 市,费用为 10。

第二个人去 a 市,费用为 30。

第三个人去 b 市,费用为 50。

第四个人去 b 市,费用为 20。

最低总费用为 10 + 30 + 50 + 20 = 110,每个城市都有一半的人在面试。

示例 2:

6
259 770
448 54
926 667
184 139
840 118
577 469
1859

示例 3:

8
515 563
451 713
537 709
343 819
855 779
457 60
650 359
631 42]
3086

提示:

  • 2n==costs.length2 * n == costs.length
  • 2<=costs.length<=1002 <= costs.length <= 100
  • costs.lengthcosts.length 为偶数
  • 1<=aCosti,bCosti<=10001 <= aCost_i, bCost_i <= 1000

SOURCE

1029. 两地调度

}