QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22638. Kuhgesellschaftstanz

Statistics

Kühe tanzen erstaunlich schlecht. Farmer John bemerkt jedoch, dass anmutige Kühe mehr Milch geben, und meldet die ganze Herde zum Gesellschaftstanz an. Beim ersten Unterricht müssen $N$ männliche Kühe, also Bullen ($1\le N\le1{,}000$), mit $N$ weiblichen Kühen gepaart werden. Ein gutes Paar hat ähnliche Höhen, also eine kleine Differenz. Finde aus allen Höhen eine Paarung mit minimaler Summe aller Höhendifferenzen.

Eingabe

  • Zeile 1: ganze Zahl $N$.
  • Zeilen $2..N+1$: je eine ganzzahlige Höhe eines Bullen.
  • Zeilen $N+2..2N+1$: je eine ganzzahlige Höhe einer Kuh.

Ausgabe

  • Zeile 1: ganzzahlige Summe der Höhendifferenzen einer optimalen Paarung.

Beispiele

Eingabe 1

4
2
8
5
5
1
4
10
7

Ausgabe 1

6

Hinweis

Eingabe

4 Bullen haben Höhen 2,8,5,5; 4 Kühe haben 1,4,10,7.

Erklärung — Ausgabe

Beste Höhenpaare: 2-1, 8-10, 5-4, 5-7. Die Summe der Differenzen ist 6.

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