Hard Sum Set Problem

3.9

8 votes
Searching algorithm, Linear search, Hard, Algorithms
Problem

Consider two sets A and B, let define their sum set S(A,B)={a+b|aA,bB}. Now given a set C, your task is to find two sets A and B such that 50|A|,50|B|,|C||S(A,B)|.

Assumption, C={c1,c2,...,cn},S(A,B)={s1,s2,...,sm},c1<c2<<cn,s1<s2<<sm. We define the score as: mni=0nj=1|cjsj+i|. You are asked to minimize the score.

Input

The first line contains an integer K denoting the number of elements of set C.

The following line contains K space-separated integers c1,c2,,cK denoting the elements of set C.

Output

Output four lines:

  • The first line contains an integer N, the number of elements of set A.
  • The second line contains N space-separated integers a1,a2,,aN, the elements of set A.
  • The third line contains an integer M, the number of elements of set B.
  • The forth line contains M space-separated integers b1,b2,,bM, the elements of set B.

Constraints

  • 1K5000.
  • 50N,M5000.
  • 1ci,ai,bi5000.

Data generation:

  • 25% tests: each number from 1 to 5000 has probability in set C is 12.
  • 25% tests: each number from 1 to 5000 has probability in set C is 13.
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Note that: The constraints on the number of elements of each set is ignored in this example.

Editor Image

?