欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1829C.Mr. Perfectly Fine
Mr. Perfectly Fine
Victor wants to become "Mr. Perfectly Fine". For that, he needs to acquire a certain set of skills. More precisely, he has skills he needs to acquire.
Victor has books. Reading book takes him minutes and will give him some (possibly none) of the required two skills, represented by a binary string of length .
What is the minimum amount of time required so that Victor acquires all of the two skills?
Input
The input consists of multiple test cases. The first line contains an integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer () — the number of books available.
Then lines follow. Line contains a positive integer () and a binary string of length , where if reading book acquires Victor skill , and otherwise, and if reading book acquires Victor skill , and otherwise.
It is guaranteed that the sum of over all test cases doesn't exceed .
Output
For each test case, output a single integer denoting the minimum amount of minutes required for Victor to obtain both needed skills and in case it's impossible to obtain the two skills after reading any amount of books.
Note
In the first test case, we can use books and , with a total amount of minutes spent equal to .
In the second test case, we can use the books and , with a total amount of minutes spent equal to .
In the third test case, we have only one option and that is reading book for a total amount of minutes spent equal to .
Samples
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
7
5
5
9
-1
8
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |