A15896 | Mr. Perfectly Fine
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Victor wants to become "Mr. Perfectly Fine". For that, he needs to acquire a certain set of skills. More precisely, he has $2$ skills he needs to acquire.
Victor has $n$ books. Reading book $i$ takes him $m_i$ minutes and will give him some (possibly none) of the required two skills, represented by a binary string of length $2$ .
What is the minimum amount of time required so that Victor acquires all of the two skills?
Victor has $n$ books. Reading book $i$ takes him $m_i$ minutes and will give him some (possibly none) of the required two skills, represented by a binary string of length $2$ .
What is the minimum amount of time required so that Victor acquires all of the two skills?
输入格式
The input consists of multiple test cases. The first line contains an integer $t$ ( $1 \leq t \leq 1000$ ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer $n$ ( $1 \leq n \leq 2 \cdot 10^5$ ) — the number of books available.
Then $n$ lines follow. Line $i$ contains a positive integer $m_i$ ( $1 \leq m_i \leq 2 \cdot 10^5$ ) and a binary string of length $2$ , where $s_{i1} = 1$ if reading book $i$ acquires Victor skill $1$ , and $s_{i1} = 0$ otherwise, and $s_{i2} = 1$ if reading book $i$ acquires Victor skill $2$ , and $s_{i2} = 0$ otherwise.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$ .
The first line of each test case contains an integer $n$ ( $1 \leq n \leq 2 \cdot 10^5$ ) — the number of books available.
Then $n$ lines follow. Line $i$ contains a positive integer $m_i$ ( $1 \leq m_i \leq 2 \cdot 10^5$ ) and a binary string of length $2$ , where $s_{i1} = 1$ if reading book $i$ acquires Victor skill $1$ , and $s_{i1} = 0$ otherwise, and $s_{i2} = 1$ if reading book $i$ acquires Victor skill $2$ , and $s_{i2} = 0$ otherwise.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$ .
输出格式
For each test case, output a single integer denoting the minimum amount of minutes required for Victor to obtain both needed skills and $-1$ in case it's impossible to obtain the two skills after reading any amount of books.
输入输出样例
输入 #1
6 4 2 00 3 10 4 01 4 00 5 3 01 3 01 5 01 2 10 9 10 1 5 11 3 9 11 8 01 7 10 6 4 01 6 01 7 01 8 00 9 01 1 00 4 8 00 9 10 9 11 8 11
输出 #1
7 5 5 9 -1 8
In the first test case, we can use books $2$ and $3$ , with a total amount of minutes spent equal to $3 + 4 = 7$ .
In the second test case, we can use the books $1$ and $4$ , with a total amount of minutes spent equal to $3 + 2 = 5$ .
In the third test case, we have only one option and that is reading book $1$ for a total amount of minutes spent equal to $5$ .
In the second test case, we can use the books $1$ and $4$ , with a total amount of minutes spent equal to $3 + 2 = 5$ .
In the third test case, we have only one option and that is reading book $1$ for a total amount of minutes spent equal to $5$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted