Under construction

Still being built. Things may change

Key to Success

Time limit3sMemory limit256 MB

Summary
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.
Level

Medium5 of 10

Topics
Greedy, Math, Sorting
Solved
No attempts yet

Problem

A television game show prepares a set of prizes for its winner. If the winner's score is XX, she must choose a subset of the available prizes whose values sum to exactly XX dollars.

The organizers already have nn spare prizes worth a1,a2,…,ana_1, a_2, \dots, a_n dollars. They do not know the winner's score in advance, so they will buy mm more prizes. Their goal is to choose those mm 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 22, 33, and 99 dollars and may buy 22 more. If they buy prizes worth 11 and 77 dollars, the winner can collect prizes for every score from 11 to 2222, so the smallest score she could not collect is 2323 — and no other purchase does better. Report that largest achievable smallest-uncollectable score.

Input

The first line contains two integers nn and mm — the number of prizes the organizers already have and the number they will buy (0≤n≤300 \le n \le 30, 1≤m≤301 \le m \le 30).

The second line contains nn integers a1,…,ana_1, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9), the values of the prizes they already have. When n=0n = 0, this line is empty.

Output

Print a single integer: over all ways to choose the mm prizes to buy, the maximum possible value of the smallest positive integer score that the winner cannot collect prizes for.

Examples3

  1. Example 1

    Input
    3 2
    2 3 9
    
    Expected output
    23
    
  2. Example 2

    Input
    0 1
    
    
    Expected output
    2
    
  3. Example 3

    Input
    5 2
    1 1 1 1 1
    
    Expected output
    24