| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 2048 MB | 51 | 17 | 15 | 33.333% |
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 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 $n$ and $w,ドル where $n$ is the number of Lower Barareh residents (1ドル \le n \le 1,円 000$), and $w$ is the maximum weight the boat can carry (1ドル \le w \le 10^6$). 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 10ドル^6$.
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.
3 7 1 3 4
3
3 4 2 3 4
-1