#P14702. [ICPC 2024 Tehran R] Boat

[ICPC 2024 Tehran R] Boat

题目描述

A river separates Upper Barareh from Lower Barareh. To transport people between these two towns, a two-seater (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 can not 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.

输入格式

The first line of the input contains two integers nn and ww, where nn is the number of Lower Barareh residents (1n10001 \leq n \leq 1000), and ww is the maximum weight the boat can carry (1w1061 \leq w \leq 10^6). The next line contains nn space-separated integers, describing the weights of the residents of Lower Barareh. All the weights are positive integers not exceeding 10610^6.

输出格式

If it is not possible to transfer all the residents of Lower Barareh, print a single line containing 1-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.

3 7
1 3 4
3
3 4
2 3 4
-1