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

Note

קלט

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.