QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 256 MB 총점: 100

#22638. 소의 사교댄스

통계

소는 춤을 아주 못 춥니다. 하지만 Farmer John은 우아한 소가 우유를 더 낸다는 걸 알아내 모두 사교댄스 수업에 등록했습니다. 첫 수업에서 $N$마리 수소 ($1\le N\le1{,}000$)와 $N$마리 암소를 짝지어야 합니다. 키가 비슷하여 차이가 작은 두 소가 좋은 짝입니다. 모든 키가 주어질 때 모든 짝의 키 차이 합을 최소화하는 짝짓기를 구하세요.

입력

  • 1줄: 정수 $N$.
  • $2..N+1$줄: 각 줄에 수소의 키를 나타내는 정수.
  • $N+2..2N+1$줄: 각 줄에 암소의 키를 나타내는 정수.

출력

  • 1줄: 최적 짝짓기의 키 차이 합을 정수로 출력합니다.

예제

입력 1

4
2
8
5
5
1
4
10
7

출력 1

6

참고

입력

수소 4마리 키는 2,8,5,5, 암소 4마리는 1,4,10,7입니다.

설명 — 출력

키로 나타낸 최적 짝은 2-1, 8-10, 5-4, 5-7이며 차이 합은 6입니다.

문제 작성: 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.