MEX of Sum

4

1 votes
Prefix Sum
Problem

Given an array  A of N integers. You have a set S which contains all possible subsequence's sum of the Array A.

Your task is to find out the MEX(S). 

subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

MEX(S) = Minimum element which is not present in the set.

for eg: MEX(0,1,3,4,6) = 2 (2 is the minimum number which is not present in the set). 

Input:

The first line contains the number of test cases t.

The first line of each test case contains the number of elements - N

The second line of each test case contains N integers - the elements of the Array A. 

The Sum of N over all test case doesn't exceed 2105.

Output:

For each test case print MEX(S).

Constraints:

1T1001N21051A[i]108

 

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Here all possible subsequences are {} {2} {1} {3} {2,1} {2,3} {1,3} {2,1,3}.

so set S= {0,2,1,3,3,5,4,6}

so MEX(S) = 7.

Editor Image

?