Skip to content

Commit

Permalink
83 완
Browse files Browse the repository at this point in the history
  • Loading branch information
seongwon02 committed Aug 17, 2024
1 parent 52c2ad6 commit 364ae5a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions SWKIM/81to90/83.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from collections import deque

def solution(people, limit):
answer = 0
people.sort() # 오름차순으로 정렬
people = deque(people)

# 무거운 사람과 가벼운 사람을 묶어 가는 것이 가장 빠름
while people:
cur = people.pop() # 무거운 사람 보트에 태움

# 가벼운 사람도 탈 수 있는 경우
if people and cur + people[0] <= limit:
cur += people[0]
people.popleft()

answer += 1

return answer

people = [40, 40, 40, 40]
limit = 160
print(solution(people, limit))

0 comments on commit 364ae5a

Please sign in to comment.