#142Medium
Missing coin sum
Time: 1 s · Memory: 256 MB
- Sorting
Statement
You have coins, each with a positive integer value. Find the smallest positive sum that cannot be made using each coin at most once.
Input format
The first line contains (). The second line contains integers ().
Output format
A single number — the smallest positive sum that cannot be made.
Examples
Input
5 2 9 1 2 7
Output
6
Input
4 1 1 1 5
Output
4
Note
Sort the coins in increasing order. Suppose the first coins can make every sum from to . If the next coin is , every sum from to can now be made. If , the sum can never be made — it is the answer.
In the first example the sorted coins are : and the next coin , so the answer is . The answer reaches — a 64-bit type is needed.
Source: CSES, problem 2183, acmp.ru, problem 427.
