#C9465. Smallest Non-formable Sum
Smallest Non-formable Sum
Smallest Non-formable Sum
Given a set of N integers, you can form new numbers by concatenating the digits of some of these integers in any order. After forming such numbers, you are allowed to add them (each used at most once) to create sums. Let \( A \) be the set of all numbers formed by concatenating one or more of the given integers, and let \( S \) be defined as:
\( S = \{\sum_{i\in I} a_i : a_i \in A, I \subseteq A\} \)
Note that \(0\) is always included in \(S\) (by taking an empty sum). Your task is to find the smallest positive integer that does not belong to \(S\). This is equivalent to finding the smallest positive integer that cannot be obtained by any combination of these concatenated numbers summed together.
Example: If the input is 3
and the list is 1 3 6
, one way to form numbers is by taking the single digits, resulting in \(\{1, 3, 6\}\). Then you can get sums like 1, 3, 6, 1+3=4, 1+6=7, 3+6=9, and 1+3+6=10. The smallest positive integer not obtainable is 2.
inputFormat
The first line of the input contains a single integer \(N\), representing the number of integers. The second line contains \(N\) space-separated integers.
outputFormat
Output a single integer, which is the smallest positive integer that cannot be formed by summing any subset of the concatenated numbers generated from the input.
## sample3
12 34 56
1
</p>