Key to Success
Time limit3sMemory limit256 MB
Given n existing coin values and m coins to add freely, choose the added values to maximize the smallest positive integer not representable as a subset sum.
Problem
A television game show prepares a set of prizes for its winner. If the winner's score is , she must choose a subset of the available prizes whose values sum to exactly dollars.
The organizers already have spare prizes worth dollars. They do not know the winner's score in advance, so they will buy more prizes. Their goal is to choose those prizes so as to maximize the smallest positive integer score that the winner would be unable to collect — that is, the smallest positive integer that cannot be written as the sum of some subset of all prizes (the ones they already have plus the ones they buy).
For example, suppose they already have prizes worth , , and dollars and may buy more. If they buy prizes worth and dollars, the winner can collect prizes for every score from to , so the smallest score she could not collect is — and no other purchase does better. Report that largest achievable smallest-uncollectable score.
Input
The first line contains two integers and — the number of prizes the organizers already have and the number they will buy (, ).
The second line contains integers (), the values of the prizes they already have. When , this line is empty.
Output
Print a single integer: over all ways to choose the prizes to buy, the maximum possible value of the smallest positive integer score that the winner cannot collect prizes for.