From 89d3d0426937834b9c8aa697426318ce4cb99ed2 Mon Sep 17 00:00:00 2001 From: heeheejj Date: Wed, 18 Oct 2023 16:32:44 +0900 Subject: [PATCH] =?UTF-8?q?Week27=20PRG=2042885=20=EA=B5=AC=EB=AA=85?= =?UTF-8?q?=EB=B3=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\353\252\205\353\263\264\355\212\270.py" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "heeheej/programmers/PRG_42885_\352\265\254\353\252\205\353\263\264\355\212\270.py" diff --git "a/heeheej/programmers/PRG_42885_\352\265\254\353\252\205\353\263\264\355\212\270.py" "b/heeheej/programmers/PRG_42885_\352\265\254\353\252\205\353\263\264\355\212\270.py" new file mode 100644 index 0000000..f543726 --- /dev/null +++ "b/heeheej/programmers/PRG_42885_\352\265\254\353\252\205\353\263\264\355\212\270.py" @@ -0,0 +1,24 @@ +# 구명보트 +''' +1270 (+11) +투포인터 이용 +몸무게를 오름차순 정렬한 뒤, +1. 두 명(몸무게가 가장 적은 사람, 몸무게가 가장 많은 사람)을 태우거나 +2. 한 명(몸무게가 가장 많은 사람)을 태운다. +l == r 인 경우는 남은 사람이 한명인 경우이므로, 무조건 answer+=1 -> while l <= r로 처리 +''' + +def solution(people, limit): + answer = 0 + people.sort() + N = len(people) + l, r = 0, N-1 + while l <= r: + answer += 1 # 구명보트 수 +1 + if people[l] + people[r] <= limit: # 두명 태울 수 있는 경우 + l += 1 + r -= 1 + else: # 두명 못태우는 경우 무거운 사람만 태운다. + r -= 1 + + return answer \ No newline at end of file