This page is still under construction.

Parts of this page are still being built. What you see may change.

Bad Packing

Time limit6sMemory limit512 MB

Summary
Given n objects and a capacity c, find the smallest total weight of a subset that cannot be extended by adding any remaining object without exceeding c.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy, Sorting, Binary search
Solved
No attempts yet

Problem

We have a knapsack of integral capacity and some objects of assorted integral sizes. We attempt to fill the knapsack up, but unfortunately, we are really bad at it, so we end up wasting a lot of space that can't be further filled by any of the remaining objects. In fact, we are optimally bad at this! How bad can we possibly be?

Figure out the least capacity we can use where we cannot place any of the remaining objects in the knapsack. For example, suppose we have 33 objects with weights 33, 55 and 33, and our knapsack has capacity 66. If we foolishly pack the object with weight 55 first, we cannot place either of the other two objects in the knapsack. That's the worst we can do, so 55 is the answer.

Input

The first line of input contains two integers nn (1≤n≤1,0001 \le n \le 1,000) and cc (1≤c≤1051 \le c \le 10^5), where nn is the number of objects we want to pack and cc is the capacity of the knapsack.

Each of the next nn lines contains a single integer ww (1≤w≤c1 \le w \le c). These are the weights of the objects.

Output

Output a single integer, which is the least capacity we can use where we cannot place any of the remaining objects in the knapsack.

Examples1

  1. Example 1

    Input
    3 6
    3
    5
    3
    
    Expected output
    5