QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 256 MB 満点: 100

#22638. 牛の社交ダンス

統計

牛は踊りがとても苦手です。しかし Farmer John は優雅な牛ほど多く乳を出すと知り、牛全員を社交ダンス教室に入れました。初回では $N$ 頭の雄牛($1\le N\le1{,}000$)と $N$ 頭の雌牛を組にします。背の高さが近く、差が小さい 2 頭はよい組です。全ての高さから、全ての組の高さの差の合計を最小にする組合せを求めてください。

入力

  • 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.