A13699 | Searchlights
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ robbers at coordinates $(a_1, b_1)$ , $(a_2, b_2)$ , ..., $(a_n, b_n)$ and $m$ searchlight at coordinates $(c_1, d_1)$ , $(c_2, d_2)$ , ..., $(c_m, d_m)$ .
In one move you can move each robber to the right (increase $a_i$ of each robber by one) or move each robber up (increase $b_i$ of each robber by one). Note that you should either increase all $a_i$ or all $b_i$ , you can't increase $a_i$ for some points and $b_i$ for some other points.
Searchlight $j$ can see a robber $i$ if $a_i \leq c_j$ and $b_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,j$ such that searchlight $j$ can see a robber $i$ ).
What is the minimum number of moves you need to perform to reach a safe configuration?
In one move you can move each robber to the right (increase $a_i$ of each robber by one) or move each robber up (increase $b_i$ of each robber by one). Note that you should either increase all $a_i$ or all $b_i$ , you can't increase $a_i$ for some points and $b_i$ for some other points.
Searchlight $j$ can see a robber $i$ if $a_i \leq c_j$ and $b_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,j$ such that searchlight $j$ can see a robber $i$ ).
What is the minimum number of moves you need to perform to reach a safe configuration?
输入格式
The first line of input contains two integers $n$ and $m$ ( $1 \leq n, m \leq 2000$ ): the number of robbers and the number of searchlight.
Each of the next $n$ lines contains two integers $a_i$ , $b_i$ ( $0 \leq a_i, b_i \leq 10^6$ ), coordinates of robbers.
Each of the next $m$ lines contains two integers $c_i$ , $d_i$ ( $0 \leq c_i, d_i \leq 10^6$ ), coordinates of searchlights.
Each of the next $n$ lines contains two integers $a_i$ , $b_i$ ( $0 \leq a_i, b_i \leq 10^6$ ), coordinates of robbers.
Each of the next $m$ lines contains two integers $c_i$ , $d_i$ ( $0 \leq c_i, d_i \leq 10^6$ ), coordinates of searchlights.
输出格式
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)$ .
The configuration of the robbers is safe, because the only searchlight can't see the robber, because it is in the coordinates $(2, 3)$ and $3 > 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)$ , $(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 $3$ moves.
The configuration of the robbers is safe, because the only searchlight can't see the robber, because it is in the coordinates $(2, 3)$ and $3 > 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)$ , $(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 $3$ moves.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted