QOJ.ac

QOJ

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

#21170. 围栏之内

Statistics

Farmer John 发现许多奶牛奇怪地患有广场恐惧症(害怕大片开阔空间)。为了让它们少怕放牧,他用竖直(南北)和水平(东西)围栏把大田分成较小区域。

大田是角点为 $(0,0)$ 和 $(A,B)$ 的矩形。FJ 在不同位置 $a_1 \ldots a_n$ ($0 < a_i < A$) 建 $n$ 条竖直围栏 ($0 \leq n \leq 2000$),每条从 $(a_i, 0)$ 到 $(a_i, B)$。又在 $b_1 \ldots b_m$ ($0 < b_i < B$) 建 $m$ 条水平围栏 ($0 \leq m \leq 2000$),每条从 $(0, b_i)$ 到 $(A, b_i)$。每条竖直围栏穿过每条水平围栏,共分出 $(n+1)(m+1)$ 个区域。

但 FJ 忘了建门,奶牛无法离开所在区域游遍田地!他想移除部分围栏以连接相邻区域。他选一些相邻区域对,移除它们间整段围栏,使奶牛能经开口到达大田任意位置。

例如以下围栏布局:

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

可以这样打开:

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

求实现目标所需移除围栏的最小总长度。

输入格式

第一行包含 $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 位整数类型(如 C/C++ 的 long long)。

样例

输入格式 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.