[프로그래머스/Python] 구명보트
·
Algorithm/Programmers
def solution(people, limit): boat = [] people.sort() light = people[0] idx = 0 for i in range(len(people)-1, -1, -1): if idx > i: break person = people[i] if person + light > limit: # 가장 가벼운 사람이랑도 못앉으면 혼자 가야지 boat.append(person) continue # 가장 가벼운 사람이랑은 같이 앉아갈 수 있다! 그럼 앉아가슈 if idx < i: boat.append(person + light) idx += 1 light = people[idx] continue # 앉아갈 짝이 없으면 혼자 가렴 boat.append(person) return ..