6739.Money Sums

Time Limit: 1s Memory Limit: 512MB

You have $n$ coins with certain values. Your task is to find all money sums you can create using these coins.

Input Format(From the terminal/stdin)

The first input line has an integer $n$ : the number of coins.

The next line has $n$ integers $x_1,x_2,\dots,x_n$ : the values of the coins.

  • $1 \le n \le 100$
  • $1 \le x_i \le 1000$

Output Format(To the terminal/stdout)

First print an integer $k$ : the number of distinct money sums. After this, print all possible sums in increasing order.

Sample Input

Copy
4
4 2 5 2
 \n
 · · · \n

Sample Output

Copy
9
2 4 5 6 7 8 9 11 13
 \n
 · · · · · · ·  ·  \n
Source: CSES, Dynamic Programming, 1745

Submit

请先 登录

© 2025 FAQs