CF1829C.Mr. Perfectly Fine

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Victor wants to become "Mr. Perfectly Fine". For that, he needs to acquire a certain set of skills. More precisely, he has 22 skills he needs to acquire.

Victor has nn books. Reading book ii takes him mim_i minutes and will give him some (possibly none) of the required two skills, represented by a binary string of length 22.

What is the minimum amount of time required so that Victor acquires all of the two skills?

Victor 想成为“完美先生”。为此,他需要掌握一套特定的技能。更准确地说,他需要掌握 2 种技能。

Victor 有 nn 本书。阅读第 ii 本书需要 mim_i 分钟,并会赋予他其中一些(可能为零)所需技能,用一个长度为 22 的二进制字符串表示。

Victor 掌握全部两种技能所需的最短时间是多少?

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤10001 \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 nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the number of books available.

Then nn lines follow. Line ii contains a positive integer mim_i (1≤mi≤2⋅1051 \leq m_i \leq 2 \cdot 10^5) and a binary string of length 22, where si1=1s_{i1} = 1 if reading book ii acquires Victor skill 11, and si1=0s_{i1} = 0 otherwise, and si2=1s_{i2} = 1 if reading book ii acquires Victor skill 22, and si2=0s_{i2} = 0 otherwise.

It is guaranteed that the sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5),表示可供阅读的书籍数量。

接下来是 nn 行。第 ii 行包含一个正整数 mim_i(1≤mi≤2⋅1051 \leq m_i \leq 2 \cdot 10^5)和一个长度为 22 的二进制字符串,其中:若阅读第 ii 本书能使 Victor 获得技能 11,则 si1=1s_{i1} = 1,否则 si1=0s_{i1} = 0;若阅读第 ii 本书能使 Victor 获得技能 22,则 si2=1s_{i2} = 1,否则 si2=0s_{i2} = 0。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \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-1 in case it's impossible to obtain the two skills after reading any amount of books.

对于每个测试用例,输出一个整数,表示 Victor 获得两项所需技能所需的最少分钟数;若无论阅读多少本书都无法获得这两项技能,则输出 −1-1。

输入输出样例

  • 输入#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 22 and 33, with a total amount of minutes spent equal to 3+4=73 + 4 = 7.

In the second test case, we can use the books 11 and 44, with a total amount of minutes spent equal to 3+2=53 + 2 = 5.

In the third test case, we have only one option and that is reading book 11 for a total amount of minutes spent equal to 55.

在第一个测试用例中,我们可以使用第 22 本和第 33 本书,总共花费的时间为 3+4=73 + 4 = 7 分钟。

在第二个测试用例中,我们可以使用第 11 本和第 44 本书,总共花费的时间为 3+2=53 + 2 = 5 分钟。

在第三个测试用例中,我们只有一种选择,即阅读第 11 本书,总共花费的时间为 55 分钟。

输入解题思路,AI测评打分。不知道怎么写?

首页