a881: Tandem Bicycle
Tags : Greedy 累加
Accepted rate : 16人/16人 ( 100% ) [非即時]
評分方式:
Tolerant

最近更新 : 2022-11-16 17:44

Content

Since time immemorial, the citizens of Dmojistan and Pegland have been at war. Now, they have finally signed a truce. They have decided to participate in a tandem bicycle ride to celebrate the truce.

There are N citizens from each country. They must be assigned to pairs so that each pair contains one person from Dmojistan and one person from Pegland. Each citizen has a cycling speed. In a pair, the fastest person will always operate the tandem bicycle while the slower person simply enjoys the ride. In other words, if the members of a pair have speeds a and b, then the bike speed of the pair is max(a, b).

The total speed is the sum of the N individual bike speeds. For this problem, in each test case, you will be asked to answer one of two questions:

• Question 1: what is the minimum total speed, out of all possible assignments into pairs?

• Question 2: what is the maximum total speed, out of all possible assignments into pairs?

Input

The first line will contain the type of question you are to solve, which is either 1 or 2.

The second line contains N (1 ≤ N ≤ 100).

The third line contains N space-separated integers: the speeds of the citizens of Dmojistan.

The fourth line contains N space-separated integers: the speeds of the citizens of Pegland.

Each person’s speed will be an integer between 1 and 1 000 000.

Output

Output the maximum or minimum total speed that answers the question asked.

Sample Input #1
1
3
5 1 4
6 2 4
Sample Output #1
12
Sample Input #2
2
3
5 1 4
6 2 4
Sample Output #2
15
Sample Input #3
2
5
202 177 189 589 102
17 78 1 496 540
Sample Output #3
2016
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (5%): 1.0s , <1M
公開 測資點#1 (5%): 0.5555555555555556s , <1K
公開 測資點#2 (5%): 0.5555555555555556s , <1K
公開 測資點#3 (5%): 0.5555555555555556s , <1M
公開 測資點#4 (5%): 0.5555555555555556s , <1K
公開 測資點#5 (5%): 0.5555555555555556s , <1M
公開 測資點#6 (5%): 0.5555555555555556s , <1M
公開 測資點#7 (5%): 0.5555555555555556s , <1M
公開 測資點#8 (6%): 0.5555555555555556s , <1M
公開 測資點#9 (6%): 0.5555555555555556s , <1M
公開 測資點#10 (6%): 0.5555555555555556s , <1K
公開 測資點#11 (6%): 0.5555555555555556s , <1K
公開 測資點#12 (6%): 0.5555555555555556s , <1M
公開 測資點#13 (6%): 0.5555555555555556s , <1K
公開 測資點#14 (6%): 0.5555555555555556s , <1M
公開 測資點#15 (6%): 0.5555555555555556s , <1M
公開 測資點#16 (6%): 0.5555555555555556s , <1M
公開 測資點#17 (6%): 0.5555555555555556s , <1M
Hint :

sort()

Tags:
Greedy 累加
出處:
CCC2016 [管理者:
issin@g.puic... (冼一心老師)
]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」