-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52c2ad6
commit 364ae5a
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |