-
카테고리
-
세부 분야
알고리즘 · 자료구조
-
해결 여부
미해결
침몰하는 타이타닉 코드
22.07.05 11:46 작성 조회수 151
0
이렇게 작성했는데 상관없나요?
N, M = map(int, input().split())
weight = list(map(int, input().split()))
weight.sort()
cnt = 0
p1 = 0
p2 = N - 1
while p1 < p2:
p2 = len(weight) - 1
if weight[p1] + weight[p2] > M:
weight.pop()
cnt += 1
else:
weight.pop(0)
weight.pop()
cnt += 1
# 한 명만 남은 경우 > 그대로 구명보트에 태워 구조
if len(weight) == 1:
cnt += 1
break
# 짝이 맞아서 리스트에 아무것도 없는 경우 > break문 사용
if weight == []:
break
print(cnt)
답변을 작성해보세요.
0
답변 1