A16358 | Diamond Theft
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Monocarp is the most famous thief in Berland. This time, he decided to steal two diamonds. Unfortunately for Monocarp, there are $n$ cameras monitoring the diamonds. Each camera has two parameters, $t_i$ and $s_i$ . The first parameter determines whether the camera is monitoring the first diamond only ( $t_i=1$ ), the second diamond only ( $t_i=2$ ), or both diamonds ( $t_i=3$ ). The second parameter determines the number of seconds the camera will be disabled after it is hacked.
Every second, Monocarp can perform one of the following three actions:
- do nothing;
- choose a camera and hack it; if Monocarp hacks the $i$ -th camera, it will be disabled for the next $s_i$ seconds (if the current second is the $T$ -th one, the camera will be disabled from the $(T+1)$ -th to the $(T+s_i)$ -th second, inclusive);
- steal a diamond if all cameras monitoring it are currently disabled. Monocarp cannot steal the second diamond if he hasn't stolen the first diamond yet.
Note that Monocarp can hack a camera multiple times, even if it is currently disabled.
Your task is to determine the minimum time it will take Monocarp to steal both diamonds, beginning with the first diamond, or report that it is impossible.
Every second, Monocarp can perform one of the following three actions:
- do nothing;
- choose a camera and hack it; if Monocarp hacks the $i$ -th camera, it will be disabled for the next $s_i$ seconds (if the current second is the $T$ -th one, the camera will be disabled from the $(T+1)$ -th to the $(T+s_i)$ -th second, inclusive);
- steal a diamond if all cameras monitoring it are currently disabled. Monocarp cannot steal the second diamond if he hasn't stolen the first diamond yet.
Note that Monocarp can hack a camera multiple times, even if it is currently disabled.
Your task is to determine the minimum time it will take Monocarp to steal both diamonds, beginning with the first diamond, or report that it is impossible.
输入格式
The first line contains a single integer $n$ ( $0 \le n \le 1500$ ) — the number of cameras.
Then $n$ lines follow, the $i$ -th of them contains two integers $t_i$ and $s_i$ ( $1 \le t_i \le 3$ ; $1 \le s_i \le 2n$ ) — the parameters of the $i$ -th camera.
Then $n$ lines follow, the $i$ -th of them contains two integers $t_i$ and $s_i$ ( $1 \le t_i \le 3$ ; $1 \le s_i \le 2n$ ) — the parameters of the $i$ -th camera.
输出格式
Print a single integer — the minimum time it will take for Monocarp to steal the first diamond first and then the second diamond. If it is impossible, print -1.
输入输出样例
输入 #1
4 2 6 1 2 1 2 2 1
输出 #1
6
输入 #2
4 2 8 3 2 3 2 3 5
输出 #2
9
输入 #3
2 3 2 2 3
输出 #3
4
输入 #4
1 3 1
输出 #4
4
输入 #5
8 2 1 2 2 3 5 3 6 1 2 1 3 1 4 1 5
输出 #5
11
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted