CF1408D.Searchlights

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn robbers at coordinates (a1,b1)(a_1, b_1), (a2,b2)(a_2, b_2), ..., (an,bn)(a_n, b_n) and mm searchlight at coordinates (c1,d1)(c_1, d_1), (c2,d2)(c_2, d_2), ..., (cm,dm)(c_m, d_m).

In one move you can move each robber to the right (increase aia_i of each robber by one) or move each robber up (increase bib_i of each robber by one). Note that you should either increase all aia_i or all bib_i, you can't increase aia_i for some points and bib_i for some other points.

Searchlight jj can see a robber ii if ai≤cja_i \leq c_j and bi≤djb_i \leq d_j.

A configuration of robbers is safe if no searchlight can see a robber (i.e. if there is no pair i,ji,j such that searchlight jj can see a robber ii).

What is the minimum number of moves you need to perform to reach a safe configuration?

有 nn 个劫匪,坐标分别为 (a1,b1)(a_1, b_1)、(a2,b2)(a_2, b_2)、…、(an,bn)(a_n, b_n);另有 mm 个探照灯,坐标分别为 (c1,d1)(c_1, d_1)、(c2,d2)(c_2, d_2)、…、(cm,dm)(c_m, d_m)。

每次操作中,你可以将所有劫匪向右移动(即每个劫匪的横坐标 aia_i 均加 1),或者将所有劫匪向上移动(即每个劫匪的纵坐标 bib_i 均加 1)。注意:你必须统一增加所有 aia_i 或统一增加所有 bib_i,不能对部分劫匪增加 aia_i、而对另一些劫匪增加 bib_i。

探照灯 jj 能够看到劫匪 ii,当且仅当 ai≤cja_i \leq c_j 且 bi≤djb_i \leq d_j。

若不存在任何一对 (i,j)(i,j) 使得探照灯 jj 能看到劫匪 ii,则称当前劫匪的配置是安全的。

为使劫匪配置变为安全状态,最少需要多少次操作?

输入格式

The first line of input contains two integers nn and mm (1≤n,m≤20001 \leq n, m \leq 2000): the number of robbers and the number of searchlight.

Each of the next nn lines contains two integers aia_i, bib_i (0≤ai,bi≤1060 \leq a_i, b_i \leq 10^6), coordinates of robbers.

Each of the next mm lines contains two integers cic_i, did_i (0≤ci,di≤1060 \leq c_i, d_i \leq 10^6), coordinates of searchlights.

输入的第一行包含两个整数 nn 和 mm(1≤n,m≤20001 \leq n, m \leq 2000):分别为劫匪的数量和探照灯的数量。

接下来的 nn 行,每行包含两个整数 aia_i、bib_i(0≤ai,bi≤1060 \leq a_i, b_i \leq 10^6),表示第 ii 个劫匪的坐标。

再接下来的 mm 行,每行包含两个整数 cic_i、did_i(0≤ci,di≤1060 \leq c_i, d_i \leq 10^6),表示第 ii 个探照灯的坐标。

输出格式

Print one integer: the minimum number of moves you need to perform to reach a safe configuration.

输出一个整数:到达安全配置所需的最少移动次数。

输入输出样例

  • 输入#1

    1 1
    0 0
    2 3

    输出#1

    3
  • 输入#2

    2 3
    1 6
    6 1
    10 1
    1 10
    7 7

    输出#2

    4
  • 输入#3

    1 2
    0 0
    0 0
    0 0

    输出#3

    1
  • 输入#4

    7 3
    0 8
    3 8
    2 7
    0 10
    5 5
    7 0
    3 5
    6 6
    3 11
    11 5

    输出#4

    6

说明/提示

In the first test, you can move each robber to the right three times. After that there will be one robber in the coordinates (3,0)(3, 0).

The configuration of the robbers is safe, because the only searchlight can't see the robber, because it is in the coordinates (2,3)(2, 3) and 3>23 \gt 2.

In the second test, you can move each robber to the right two times and two times up. After that robbers will be in the coordinates (3,8)(3, 8), (8,3)(8, 3).

It's easy the see that the configuration of the robbers is safe.

It can be proved that you can't reach a safe configuration using no more than 33 moves.

在第一个测试用例中,你可以将每个劫匪向右移动三次。之后,将有一个劫匪位于坐标 (3,0)(3, 0) 处。

该劫匪布局是安全的,因为唯一的探照灯无法看到该劫匪——探照灯位于坐标 (2,3)(2, 3),而 3>23 > 2。

在第二个测试用例中,你可以将每个劫匪向右移动两次、向上移动两次。之后,劫匪将位于坐标 (3,8)(3, 8) 和 (8,3)(8, 3) 处。

显然,该劫匪布局是安全的。

可以证明:使用不超过 33 次移动无法达到安全布局。

输入解题思路,AI测评打分。不知道怎么写?

首页