QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#22638. Bovine Ballroom Dancing

Estadísticas

Cows are remarkably bad dancers. Nonetheless, Farmer John has discovered that graceful cows tend to produce more milk and therefore has enrolled his entire herd cows in a ballroom dance class. In the first class meeting, the $N$ ($1 \le N \le 1{,}000$) boy cows (a.k.a. bulls) and $N$ girl cows in the herd must first be paired up into couples. Two cows make a good couple if they have relatively similar heights (i.e., the difference of their heights is small). Given the heights of all the cows, your task is to find a pairing-up of the cows that minimizes the total sum of all height differences over all couples.

Input

  • Line 1: The single integer $N$.
  • Lines 2..$N$+1: Each line contains an integer giving the height of a boy cow.
  • Lines $N$+2..2N+1: Each line contains an integer giving the height of a girl cow.

Output

  • Line 1: A single integer giving the sum of height differences in an "optimal" pairing up of the cows.

Examples

Input 1

4
2
8
5
5
1
4
10
7

Output 1

6

Input Details

There are 4 boy cows of heights 2, 8, 5, and 5, and there are 4 girl cows of heights 1, 4, 10, and 7.

Output Details

The best pairing is as follows (in terms of heights): 2-1 8-10 5-4 5-7. The total sum of height difference for this pairing is 6.

Problem credits: Brian Dean, 2004

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.