A tasting tray holds n samples, each of a whole-number size. Consider every possible subset of the samples, including the empty subset (whose total size is 0). Count how many distinct total sizes are achievable across all subsets. Two subsets that share the same total count as one distinct total.
Line 1: an integer n.
Line 2: n space-separated integers, the sample sizes.
A single integer: the number of distinct achievable subset totals (0 is always one of them).
Example 1
Input
3 1 2 4
Expected
8
Explanation
Subset totals range over 0,1,2,3,4,5,6,7 - every value from 0 to 7 is reachable, giving 8 distinct totals.
Example 2
Input
3 2 2 2
Expected
4
Explanation
Only totals 0, 2, 4 and 6 are possible, so there are 4 distinct totals.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →