#C11088. Smallest Non-Representable Subset Sum

    ID: 40365 Type: Default 1000ms 256MiB

Smallest Non-Representable Subset Sum

Smallest Non-Representable Subset Sum

You are given an array of positive integers. Your task is to find the smallest positive integer that cannot be represented as the sum of some subset of the given array. Formally, if the array elements are denoted by \(a_1, a_2, \dots, a_n\), you must determine the smallest integer \(S\) such that it is impossible to find a subset of \(\{a_1, a_2, \dots, a_n\}\) whose sum equals \(S\).

Example:

Input: 3
       1 2 3
Output: 7

In this example, every number from 1 to 6 can be represented as a sum of subset elements, but 7 cannot.

Note: The input is provided via standard input (stdin) and the output must be printed to standard output (stdout).

inputFormat

The first line of input contains a single integer \(n\) denoting the number of elements in the array. The second line contains \(n\) space-separated positive integers.

Example:

3
1 2 3

outputFormat

Print a single integer: the smallest positive integer that cannot be represented as the sum of a subset of the array elements.

Example:

7
## sample
3
1 2 3
7

</p>