#QHD0000073. Những giá trị có thể tạo thành (The Values You Can Make)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những giá trị có thể tạo thành (The Values You Can Make)
The Values You Can Make
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Pari owns coins. Coin has positive integer value . To buy chocolate priced at exactly , she must choose a subset of her coins whose total value is exactly and hand all chosen coins to Arya. Each physical coin may be used at most once; equal-valued coins in different positions are distinct.
Arya may then select any subset of the coins she received, possibly the empty subset. Determine all integer values Arya could form for at least one valid way Pari pays. Formally, a value is possible if there exist index sets satisfying
The inner subset may be empty, so is allowed. Arya may select all received coins, so is allowed. Report each feasible value only once. It is not sufficient for to be a subset sum of the original coins: its coins must fit inside a valid exact- payment. A payment of total is guaranteed to exist.
Input
The first line contains . The second line contains exactly integers .
Output
Print the number of feasible values on the first line. Print the distinct values in ascending order on the second line, separated by spaces.
Subtasks
-
Subtask 1 (20 points): ; ; ; an exact- subset exists.
-
Subtask 2 (30 points): ; ; ; an exact- subset exists.
-
Subtask 3 (50 points): ; ; an exact- subset exists.
Examples
Example 1
Input
6 18
5 6 1 10 12 2
Output
16
0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18
Explanation
For instance, paying permits amounts . Other exact payments yield more values. Taking the union of all valid inner subset sums produces the reported amounts.
Example 2
Input
3 50
25 25 50
Output
3
0 25 50
Explanation
Paying with the -coin or with both -coins is valid. Only the latter allows Arya to form . The complete set is .