코드
from collections import deque
def solution(people, limit):
answer = 0
people.sort(reverse=True)
people=deque(people)
while people:
tmp=0
tmp+=people.popleft()
if not people:
answer+=1
break
if tmp+people[0]<=limit:
people.popleft()
answer+=1
elif tmp+people[-1]<=limit:
people.pop()
answer+=1
else:
answer+=1
return answer
다른 사람의 풀이
def solution(people, limit) :
answer = 0
people.sort()
a = 0
b = len(people) - 1
while a < b :
if people[b] + people[a] <= limit :
a += 1
answer += 1
b -= 1
return len(people) - answer