7069.Same Sum Subsets

Time Limit: 1s Memory Limit: 512MB

Given a set of $n$ positive integers, your task is to choose two disjoint subsets of the elements that have the same sum.

Input Format(From the terminal/stdin)

The first line has an integer $n$ : the set size.

The second line has $n$ integers $x_1,x_2,\dots,x_n$ : the set elements.

  • $3 \le n \le 40$
  • $\sum_{i=1}^{n} x_i \le 2^{n}-2$

Output Format(To the terminal/stdout)

For both subsets, first print the size of the subset and then its contents. You can print any valid solution. If there is no solution, print IMPOSSIBLE.

Sample Input

Copy
6
1 2 3 5 7 8
 \n
 · · · · · \n

Sample Output special judge

Copy
2
2 3
1
5
 \n
 · \n
 \n
 \n

The first subset is ${2,3}$ and the second subset is ${5}$ .

Source: CSES, Additional Problems II, 3425

Submit

请先 登录

© 2025 FAQs