백준 2217 문제

백준 2217 풀이
이 문제는 ‘모든 로프가 견딜 수 있는 무게를 계산할 수 있는가?’가 중요한 문제였다. 그렇다면 그 무게를 어떻게 계산하느냐인데, 그건 ‘로프의 개수’ * ‘가장 약한 로프가 견딜 수 있는 무게’ 이렇게 곱하면 얻을 수 있다.
# 2217
import sys
# 입력
n = int(sys.stdin.readline())
lst = []
for i in range(n):
s = int(sys.stdin.readline())
lst.append(s)
# 무게 내림차순 정렬
lst.sort(reverse=True)
# 들 수 있는 무게 계산
cnt = 0 # 지금까지 로프 개수
weights = 0 # 현재 로프로 들 수 있는 무게
max_weight = 0 # 로프로 들 수 있는 최대 무게
# 로프로 들 수 있는 무게 = 제일 약한 로프가 버틸 수 있는 무게 * 총 로프 개수
for i in lst:
cnt +=1
weights = i * cnt
# 최대값 갱신
if weights > max_weight:
max_weight = weights
# 출력
print(max_weight)
No Responses