CF1032E.The Unbearable Lightness of Weights

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have a set of nn weights. You know that their masses are a1a_1, a2a_2, ..., ana_n grams, but you don't know which of them has which mass. You can't distinguish the weights.

However, your friend does know the mass of each weight. You can ask your friend to give you exactly kk weights with the total mass mm (both parameters kk and mm are chosen by you), and your friend will point to any valid subset of weights, if it is possible.

You are allowed to make this query only once. Find the maximum possible number of weights you can reveal after this query.

你有一组 nn 个砝码。你知道它们的质量分别为 a1a_1, a2a_2, ..., ana_n 克,但你不知道每个砝码对应哪个质量,且这些砝码外观无法区分。

然而,你的朋友知道每个砝码的确切质量。你可以向朋友提出一次查询:指定一个整数 kk 和一个整数 mm,请求朋友为你选出恰好 kk 个砝码,使其总质量恰好为 mm;如果存在满足条件的砝码子集,朋友将任选一个并指出其中的砝码(即告诉你哪些砝码被选中)。

你仅被允许进行一次这样的查询。问:在最优策略下,你最多能确定多少个砝码的质量?

输入格式

The first line contains a single integer nn (1≤n≤1001 \le n \le 100) — the number of weights.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1001 \le a_i \le 100) — the masses of the weights.

第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 表示砝码的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1001 \le a_i \le 100)—— 表示各砝码的质量。

输出格式

Print the maximum number of weights you can learn the masses for after making a single query.

输出在进行一次查询后,你能确定质量的最大砝码数量。

输入输出样例

  • 输入#1

    4
    1 4 2 2

    输出#1

    2
  • 输入#2

    6
    1 2 4 4 4 9

    输出#2

    2

说明/提示

In the first example we can ask for a subset of two weights with total mass being equal to 44, and the only option is to get 2,2{2, 2}.

Another way to obtain the same result is to ask for a subset of two weights with the total mass of 55 and get 1,4{1, 4}. It is easy to see that the two remaining weights have mass of 22 grams each.

In the second example we can ask for a subset of two weights with total mass being 88, and the only answer is 4,4{4, 4}. We can prove it is not possible to learn masses for three weights in one query, but we won't put the proof here.

在第一个例子中,我们可以查询一个总质量为 44 的两个砝码的子集,唯一可能的结果是得到 {2,2}\{2, 2\}。

另一种获得相同结果的方式是查询一个总质量为 55 的两个砝码的子集,并得到 {1,4}\{1, 4\}。显然,剩余的两个砝码质量均为 22 克。

在第二个例子中,我们可以查询一个总质量为 88 的两个砝码的子集,唯一可能的结果是 {4,4}\{4, 4\}。可以证明:仅通过一次查询无法确定三个砝码的质量,但此处不给出该证明。

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

首页