Recent Posts
«   2024/11   »
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
Today
Total
관리 메뉴

Try

[Programmers/Python] 구명보트 본문

Algorithm/Programmers

[Programmers/Python] 구명보트

HAS3ONG 2019. 3. 23. 21:39

출처

https://programmers.co.kr/learn/courses/30/lessons/42885?language=python3



소스

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
def solution(p, limit):
    answer = 0
    boat = 0
    i = 0
    j = len(p) - 1
    
    p.sort()
    p.reverse()
    
    while(1):
        if i > j:
            break
        elif i == j:
            boat = boat+1
            break
            
        if p[i] + p[j] > limit:
            i = i + 1
            boat = boat+1
        else:
            i = i + 1
            j = j - 1
            boat = boat+1
            
    answer = boat
    return answer
cs


Comments