QOJ.ac

QOJ

时间限制: 10 s - 20 s 内存限制: 1024 MB 总分: 43

#5889. 相等和

统计

我有一个正整数集合 $S$。你能找到两个非空且不同的子集,使得它们的元素之和相等吗?

注意:子集是指仅包含 $S$ 中元素的集合,如果两个子集所包含的元素不完全相同,则它们是不同的。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来有 $T$ 行,每行对应一个测试用例。每个测试用例以 $N$ 开头,表示集合 $S$ 中正整数的个数。随后是 $N$ 个不同的正整数,均在同一行内。

输出格式

对于每个测试用例,首先输出一行 "Case #x:",其中 $x$ 是测试用例的编号(从 1 开始)。

  • 如果存在两个不同的子集,其元素之和相等,则输出这两个子集,每行一个。每行应包含该子集中的数字,并用空格分隔。
  • 如果不存在这样的子集,则输出字符串 "Impossible"。

如果存在多种选择两个和相等子集的方法,输出其中任意一种即可。

数据范围

$S$ 中的数字互不相同。

$1 \le T \le 10$。

子任务 1(可见判定;6 分)

$N$ 恰好等于 20。

$S$ 中的每个数字都是小于 $10^5$ 的正整数。

子任务 2(隐藏判定;37 分)

$N$ 恰好等于 500。

$S$ 中的每个数字都是小于 $10^{12}$ 的正整数。

样例

输入格式 1

2
20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
20 120 266 858 1243 1657 1771 2328 2490 2665 2894 3117 4210 4454 4943 5690 6170 7048 7125 9512 9600

输出格式 1

Case #1: 
1 2
3
Case #2: 
1243 1771
120 2894

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.