CF1886F.Diamond Theft
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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, ti and si. The first parameter determines whether the camera is monitoring the first diamond only (ti=1), the second diamond only (ti=2), or both diamonds (ti=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 si seconds (if the current second is the T-th one, the camera will be disabled from the (T+1)-th to the (T+si)-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.
莫诺卡普是贝尔兰最著名的窃贼。这一次,他决定偷两颗钻石。不幸的是,有 n 个摄像头正在监视这两颗钻石。每个摄像头有两个参数:ti 和 si。第一个参数 ti 表示该摄像头监视哪颗钻石:仅监视第一颗钻石(ti=1),仅监视第二颗钻石(ti=2),或同时监视两颗钻石(ti=3)。第二个参数 si 表示该摄像头被黑掉后将失效的秒数。
每一秒,莫诺卡普可以执行以下三种操作之一:
- 什么也不做;
- 选择一个摄像头并黑掉它;若莫诺卡普黑掉了第 i 个摄像头,则该摄像头将在接下来的 si 秒内失效(若当前为第 T 秒,则该摄像头将在第 T+1 秒至第 T+si 秒(含)期间失效);
- 偷取一颗钻石——前提是所有正在监视该钻石的摄像头当前均处于失效状态。但莫诺卡普必须先偷走第一颗钻石,才能偷第二颗钻石。
注意:莫诺卡普可以多次黑掉同一个摄像头,即使该摄像头当前正处于失效状态。
你的任务是求出莫诺卡普偷走两颗钻石(按顺序先偷第一颗、再偷第二颗)所需的最短时间;若不可能完成,则报告这一点。
输入格式
The first line contains a single integer n (0≤n≤1500) — the number of cameras.
Then n lines follow, the i-th of them contains two integers ti and si (1≤ti≤3; 1≤si≤2n) — the parameters of the i-th camera.
第一行包含一个整数 n(0≤n≤1500)—— 表示摄像头的数量。
接下来有 n 行,其中第 i 行包含两个整数 ti 和 si(1≤ti≤3;1≤si≤2n)—— 表示第 i 个摄像头的参数。
输出格式
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.
输出一个整数——Monocarp 先窃取第一颗钻石、再窃取第二颗钻石所需的最短时间。如果无法实现,则输出 −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
输入解题思路,AI测评打分。不知道怎么写?