#K11596. Smallest Nonrepresentable Sum
Smallest Nonrepresentable Sum
Smallest Nonrepresentable Sum
You are given T test cases. Each test case consists of a list of positive integers. For each test case, determine the smallest positive integer that cannot be represented as the sum of any subset of the given list of integers.
In other words, given a sorted list \(a_1, a_2, \ldots, a_n\), let \(R\) be the maximum sum that can be formed using a subset of the numbers seen so far (initially \(R = 0\)). If the next number, \(a_i\), is such that \(a_i > R + 1\), then \(R + 1\) cannot be represented as the sum of any subset of the numbers; otherwise, update \(R = R + a_i\). The answer for that test case is \(R + 1\) when this condition first occurs, or after processing all numbers.
Input/Output Details:
- The first line of input contains an integer \(T\), the number of test cases.
- Each of the next \(T\) lines contains a space-separated list of positive integers representing a test case.
- For each test case, output the smallest positive integer that cannot be represented as the sum of any subset of the provided numbers.
Example:
Input: 2 1 2 3 1 2 2 7</p>Output: 7 6
inputFormat
The input is provided via standard input (stdin) as follows:
- The first line contains an integer \(T\) which denotes the number of test cases.
- Each of the following \(T\) lines contains a space-separated list of positive integers.
outputFormat
For each test case, output the smallest positive integer that cannot be represented as the sum of any subset of the numbers in that test case. Each answer should be printed on a new line to standard output (stdout).
## sample2
1 2 3
1 2 2 7
7
6
</p>