PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000043. Các tổng tiền có thể tạo (Money Sums)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Các tổng tiền có thể tạo (Money Sums)
Money Sums
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
You have individual coins. Coin has value . Each coin can be used at most once; equal-valued coins still count as separate coins. Consider all selections containing at least one coin and sum the selected values. List every distinct positive attainable sum in increasing order.
Input
The first line contains . The next line contains coin values .
Output
Print the number of distinct sums on the first line, then the positive sums in increasing order on the next line.
Subtasks
The independent scoring groups have the following complete constraints:
- Subtask 1 (20%): , .
- Subtask 2 (30%): , .
- Subtask 3 (50%): , .
Examples
Input
4
4 2 5 2
Output
9
2 4 5 6 7 8 9 11 13
Explanation
From coins , the distinct positive reachable sums are . There are of them and they must be printed in increasing order.