Hanbit the Developer

[그리디] Python - 2217번 로프 본문

Algorithm/백준

[그리디] Python - 2217번 로프

hanbikan 2021. 2. 22. 20:53
N = int(input())
ropes = []
for _ in range(N): ropes.append(int(input()))
ropes.sort(reverse=True)
maxWeight = 0
for i in range(len(ropes)):
    maxWeight = max(maxWeight, ropes[i]*(i+1))
print(maxWeight)

버틸 수 있는 중량(ropes)를 오름차순으로 정렬한 뒤, for문을 돌면서 최대 중량을 (현재 로프의 중량)*(지금까지 로프 갯수)를 통해 갱신시켜준다.