LCC '24 Contest 3 J5 - Bob to the Rescue!

View as PDF

Submit solution


Points: 7
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

In the Arctic Ocean, there lives a special species of penguins that can fly, but cannot swim. However, these penguins love the water, so they came up with a solution - they'd wrap ropes around their bodies so other penguins can pull them back up! Despite this ingenious invention of rope to allow the penguins to swim, not all of the penguins are the brightest creatures on the planet, and often forget to tie a rope to them before diving underwater. In fact, Bob the penguin was specifically delegated the job of reminding other penguins to wrap a piece of rope around them before leaving.

Unfortunately, penguins sometimes slip into the water, and it is Bob's job to rescue these penguins from the ocean with the N rope segments he is given, with the ith segment having a unique integer length of l_i meters, and thickness 1 centimeter. Bob can tie exactly two pieces of rope together to form a longer piece of rope(assume no length is used for the knot). Then, he can wrap any newly formed or remaining rope segments with the same length together to form a thicker rope to use for the rescue mission.

Since this is a rescue mission, Bob wants the rope used to be as thick as possible given that it is long enough to reach the fallen penguin, who is x meters away from Bob. Note that Bob does NOT have to use all the ropes.

Input Specification

The first line of input will contain two space-separated integers N and x, representing the number of ropes Bob has and the distance of the fallen penguin from Bob, in meters.

The second line of input will contain N space-separated integers, with the ith integer representing l_i, the length of the ith rope.

Output Specification

Output one integer t, the thickness of the thickest rope that can be formed, in centimeters, or -1 if the penguin cannot be reached.

Subtasks

For all test cases,

1 \le N \le 1000

1 \le x \le 2 \times 10^7

1 \le l_i \le 10^7

Subtask 1 [25%]

1 \le N \le 4

Subtask 2 [75%]

No additional constraints.

Sample Input 1

5 4
1 5 2 4 6

Sample Output 1

3

Explanation for Sample Input 1

Bob can tie the ropes with length 1 and 5 together to form a rope with length 6, and the ropes with length 2 and 4 to do the same. Then, he can wrap the 3 ropes with length 3 together to form a rope with thickness 3 and length 6, which is long enough to reach the fallen penguin.


Comments

There are no comments at the moment.