Smallest Impossible Sum
Using each coin at most once, sums are formed as subsets of the coins. Print the smallest positive integer that is NOT representable.
Input: the first line has N; the second line has N positive coin values.
Output: the smallest positive unreachable subset sum.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ ai ≤ 109
Sample Tests
Input 1
4 1 1 3 5
Output 1
11
Input 2
2 2 3
Output 2
1
Discussion (opens after you solve — no spoilers before)
No comments yet.