Boat
A river separates Upper Barareh from Lower Barareh. To transport people between these two towns, a two-seater boat (a boat that can carry at most two people) with a certain weight capacity has been provided. This boat must be steered by at least one person, i.e. it cannot move across the river without any passengers.
The National Barareh Festival is scheduled to be held in Upper Barareh. All Lower Barareh residents want to participate in this celebration and need to move to Upper Barareh as quickly as possible. Your task is to help them move to Upper Barareh with the minimum number of boat trips across the river.
Input
The first line of the input contains two integers n and w, where n is the number of Lower Barareh residents (1≤n≤1000), and w is the maximum weight the boat can carry (1≤w≤106). The next line contains n space-separated integers, describing the weights of the residents of Lower Barareh. All the weights are positive integers not exceeding 106.
Output
If it is not possible to transfer all the residents of Lower Barareh, print a single line
containing -1 in the output. Otherwise, print the minimum number of times the boat must
travel between Lower Barareh and Upper Barareh (in both directions) in order to transfer
all residents of Lower Barareh to Upper Barareh.
Constraints
- 1≤n≤1000
- 1≤w≤106
- Weights are positive integers at most 106
Example 1
3 7
1 3 4
3
Example 2
3 4
2 3 4
-1
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.