QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100

#22638. Ballo da sala bovino

统计

Le mucche ballano davvero male. Farmer John nota però che quelle aggraziate producono più latte e iscrive tutta la mandria a un corso di ballo da sala. Alla prima lezione $N$ maschi, cioè tori ($1\le N\le1{,}000$), e $N$ femmine devono formare coppie. Una buona coppia ha altezze simili, con differenza piccola. Date tutte le altezze, trova coppie che minimizzino la somma delle differenze.

Input

  • Riga 1: intero $N$.
  • Righe $2..N+1$: un intero per riga, altezza di un maschio.
  • Righe $N+2..2N+1$: un intero per riga, altezza di una femmina.

Output

  • Riga 1: intero, somma delle differenze in un abbinamento ottimo.

Esempi

Input 1

4
2
8
5
5
1
4
10
7

Output 1

6

Note

Input

4 maschi hanno altezze 2,8,5,5 e 4 femmine 1,4,10,7.

Spiegazione — Output

Migliori coppie per altezza: 2-1, 8-10, 5-4, 5-7. Somma delle differenze 6.

Autore: 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.