QOJ.ac

QOJ

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

#21170. Eingezäunt

Statistics

Farmer John erkennt, dass viele Kühe seltsam agoraphobisch sind (Angst vor großen offenen Flächen). Um die Angst vor dem Grasen zu mindern, teilt er das Feld mit vertikalen (Nord-Süd) und horizontalen (Ost-West) Zäunen in kleinere Gebiete.

Das Feld ist ein Rechteck mit Ecken $(0,0)$ und $(A,B)$. FJ baut $n$ vertikale Zäune ($0 \leq n \leq 2000$) an verschiedenen Stellen $a_1 \ldots a_n$ ($0 < a_i < A$), von $(a_i, 0)$ nach $(a_i, B)$. Auch $m$ horizontale ($0 \leq m \leq 2000$) bei $b_1 \ldots b_m$ ($0 < b_i < B$), von $(0, b_i)$ nach $(A, b_i)$. Jeder vertikale kreuzt jeden horizontalen, sodass $(n+1)(m+1)$ Gebiete entstehen.

Er vergaß Tore, sodass die Kühe ihr Gebiet nicht verlassen und das Feld durchwandern können! Er entfernt Stücke zwischen Nachbargebieten. Für einige gewählte benachbarte Paare entfernt er den gesamten trennenden Zaun, damit Kühe durch Öffnungen überallhin gelangen.

Beispielsweise dieses Muster:

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

kann so geöffnet werden:

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

Bestimme die kleinste gesamte Zaunlänge, die dafür entfernt werden muss.

Eingabe

Die erste Zeile enthält $A$, $B$, $n$, $m$ ($1 \leq A, B \leq 1,000,000,000$). Die nächsten $n$ Zeilen enthalten $a_1 \ldots a_n$, dann $m$ Zeilen $b_1 \ldots b_m$.

Ausgabe

Gib die minimale entfernte Länge aus. Sie kann eine normale 32-Bit-Ganzzahl übersteigen; eventuell sind 64-Bit-Typen wie long long in C/C++ nötig.

Beispiele

Eingabe 1

15 15 5 2
2
5
10
6
4
11
3

Ausgabe 1

44

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