Logo
(追記) (追記ここまで)

33201번 - Boat 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB51171533.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.

제한

예제 입력 1

3 7
1 3 4

예제 출력 1

3

예제 입력 2

3 4
2 3 4

예제 출력 2

-1

힌트

출처

ICPC > Regionals > Asia West Continent > Iran > 2024 ICPC Asia Tehran Regional Contest K번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /