알고리즘
[ 프로그래머스 ] 구명보트
황성안
2021. 9. 17. 23:36
728x90
반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import math def solution(people, limit): answer = 0 # all_w = 0 # for i in people: # all_w += i # check_w = all_w/limit # print(check_w%limit) # if all_w % limit == 0: # answer = check_w+1 # else: # answer = math.ceil(check_w) #ㅋㅋㅋㅋㅋㅋㅋ sort_mans = sorted(people) help = 0 mans = len(people)-1 ship = 0 while help <= mans: ship+=1 if sort_mans[mans] + sort_mans[help] <= limit: help+=1 mans-=1 answer = ship return answer | cs |
728x90
반응형