QOJ.ac

QOJ

时间限制: 2 s - 4 s 内存限制: 1024 MB 总分: 25

#5856. 糖果分配

统计

Sean 和 Patrick 是两兄弟,他们刚从父母那里得到了一袋糖果。每块糖果都有一个正整数价值,孩子们想把这些糖果分给彼此。首先,Sean 会把糖果分成两堆,并选择其中一堆给 Patrick。然后 Patrick 会尝试计算每一堆的价值(一堆的价值是其中所有糖果价值的总和);如果他认为两堆的价值不相等,他就会哭。

不幸的是,Patrick 年纪还小,不知道如何正确地进行加法。他几乎知道如何进行二进制加法;但当他把两个 1 相加时,他总是忘记向下一位进位。例如,如果他想计算 12(二进制为 1100)和 5(二进制为 101)的和,他会正确地计算最右侧的两位,但在第三位时,他会忘记向下一位进位:

1100
+ 0101
------
1001

因此,在不考虑第三位进位的情况下完成最后一位的加法后,最终结果是 9(二进制为 1001)。以下是 Patrick 数学能力的其他一些例子:

5 + 4 = 1
7 + 9 = 14
50 + 10 = 56

Sean 非常擅长加法,他想在不让弟弟哭的前提下尽可能多地获取糖果价值。如果可能的话,他会将这袋糖果分成两个非空堆,使得 Patrick 认为两堆的价值相等。给定袋中所有糖果的价值,我们想知道这是否可能;如果可能,请确定 Sean 那一堆糖果的最大可能价值。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例由两行组成。第一行包含一个整数 $N$,表示袋中糖果的数量。下一行包含 $N$ 个整数 $C_i$,用空格分隔,表示袋中每块糖果的价值。

输出格式

对于每个测试用例,输出一行 "Case #x: y",其中 $x$ 是用例编号(从 1 开始)。如果 Sean 无法阻止 Patrick 哭泣,则 $y$ 应为单词 "NO"。否则,$y$ 应为 Sean 保留的那一堆糖果的价值。

数据范围

$1 \le T \le 100$。 $1 \le C_i \le 10^6$。 内存限制:1GB。

小数据集(测试集 1 - 可见;10 分)

$2 \le N \le 15$。 时间限制:2 秒。

大数据集(测试集 2 - 隐藏;15 分)

$2 \le N \le 1000$。 时间限制:4 秒。

样例

样例输入 1

2
5
1 2 3 4 5
3
3 5 6

样例输出 1

Case #1: NO
Case #2: 11

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.