CF1826A.Trust Nobody

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a group of nn people. Some of them might be liars, who always tell lies. Other people always tell the truth. The ii-th person says "There are at least lil_i liars amongst us". Determine if what people are saying is contradictory, or if it is possible. If it is possible, output the number of liars in the group. If there are multiple possible answers, output any one of them.

有 nn 个人组成的一个群体。其中一些人可能是说谎者,他们总是说谎;其余的人则总是说真话。第 ii 个人声称:“我们之中至少有 lil_i 个说谎者”。判断这些人的陈述是否矛盾,或者是否可能成立。如果可能成立,请输出该群体中说谎者的数量;如果有多个可能的答案,输出其中任意一个即可。

输入格式

The first line contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1001 \leq n \leq 100).

The second line of each test case contains nn integers lil_i (0≤li≤n0 \leq l_i \leq n) — the number said by the ii-th person.

It's guaranteed that the sum of all nn does not exceed 10410^4.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000)—— 表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)。

每个测试用例的第二行包含 nn 个整数 lil_i(0≤li≤n0 \leq l_i \leq n)—— 表示第 ii 个人所说的数字。

保证所有 nn 的总和不超过 10410^4。

输出格式

For each test case output a single integer. If what people are saying is contradictory, output −1-1. Otherwise, output the number of liars in the group. If there are multiple possible answers, output any one of them.

对每个测试用例,输出一个整数。如果人们所说的话相互矛盾,则输出 −1-1;否则,输出该群体中说谎者的人数。如果存在多个可能的答案,输出其中任意一个即可。

输入输出样例

  • 输入#1

    7
    2
    1 2
    2
    2 2
    2
    0 0
    1
    1
    1
    0
    5
    5 5 3 3 5
    6
    5 3 6 6 3 5

    输出#1

    1
    -1
    0
    -1
    0
    3
    4

说明/提示

In the first example, the only possible answer is that the second person is a liar, so the answer is 11 liar.

In the second example, it can be proven that we can't choose the liars so that all the requirements are satisfied.

In the third example, everybody tells the truth, so the answer is 00 liars.

在第一个例子中,唯一可能的答案是第二个人说谎,因此答案是 11 个说谎者。

在第二个例子中,可以证明:无法选择说谎者使得所有要求均被满足。

在第三个例子中,所有人都说真话,因此答案是 00 个说谎者。

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

首页