QOJ.ac

QOJ

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

#21170. בתוך הגדרות

Statistics

Farmer John גילה שרבות מהפרות סובלות באופן מוזר מאגורפוביה (פחד ממרחבים פתוחים גדולים). כדי להפחית פחד מרעייה הוא מחלק את שדהו בגדרות אנכיות (צפון-דרום) ואופקיות (מזרח-מערב) לאזורים קטנים.

השדה מלבן עם פינות $(0,0)$ ו־$(A,B)$. FJ בונה $n$ גדרות אנכיות ($0 \leq n \leq 2000$) במקומות שונים $a_1 \ldots a_n$ ($0 < a_i < A$), מ־$(a_i, 0)$ ל־$(a_i, B)$. גם $m$ אופקיות ($0 \leq m \leq 2000$) במקומות $b_1 \ldots b_m$ ($0 < b_i < B$), מ־$(0, b_i)$ ל־$(A, b_i)$. כל אנכית חוצה כל אופקית, ויוצרת $(n+1)(m+1)$ אזורים.

שכח שערים ולכן פרות לא יכולות לצאת מאזורן ולטייל בכל השדה! יסיר חלקי גדר בין אזורים שכנים. יבחר כמה זוגות שכנים ויסיר את כל אורך הגדר המפרידה כדי שדרך הפתחים הפרות יוכלו להגיע לכל מקום.

למשל תבנית זו:

+---+--+
|   |  |
+---+--+
|   |  |  
|   |  |
+---+--+

אפשר לפתוח כך:

+---+--+
|      |  
+---+  +  
|      |  
|      |
+---+--+

מצאו את האורך הכולל המזערי להסרה כדי להשיג את המטרה.

קלט

השורה הראשונה מכילה $A$, $B$, $n$, $m$ ($1 \leq A, B \leq 1,000,000,000$). $n$ הבאות מכילות $a_1 \ldots a_n$, ואז $m$ הבאות $b_1 \ldots b_m$.

פלט

הדפיסו את האורך המזערי להסרה. עלול לחרוג משלם רגיל 32 ביט, וייתכן צורך בטיפוס 64 ביט כמו long long ב־C/C++.

דוגמאות

קלט 1

15 15 5 2
2
5
10
6
4
11
3

פלט 1

44

מחבר הבעיה: Brian Dean

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.