Possible Money Sums

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 512M
Input: stdin
Output: stdout

Author:
Problem type
Allowed languages
C++, pypy3, Python

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

Input:

  • The first line contains an integer n: the number of coins.
  • The second line contains n integers x_1, x_2, \dots, x_n: the values of the coins.

Output:

  • First, print an integer k: the number of distinct money sums that can be formed using any subset of the coins (each coin used at most once).
  • Then, print all such sums in increasing order, separated by spaces.

Constraints:

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

Example:

Sample Input:

4
4 2 5 2

Sample Output:

  9
  2 4 5 6 7 8 9 11 13

Comments

There are no comments at the moment.