DHistory

[Baekjoon] Greedy - 2217 로프 본문

Computer Science/Algorithm

[Baekjoon] Greedy - 2217 로프

ddu0422 2023. 8. 16. 11:15

문제

 

2217번: 로프

N(1 ≤ N ≤ 100,000)개의 로프가 있다. 이 로프를 이용하여 이런 저런 물체를 들어올릴 수 있다. 각각의 로프는 그 굵기나 길이가 다르기 때문에 들 수 있는 물체의 중량이 서로 다를 수도 있다. 하

www.acmicpc.net

 

풀이

"""
N개의 로프
- 로프는 들 수 있는 물체의 중량이 서로 다를 수 있다.
- 여러 개의 로프를 병렬로 연결하는 경우 w/k로 고르게 들 수있다.

로프들을 이용하여 들어올릴 수 있는 물체의 최대 중량은?
"""
import sys

n = int(sys.stdin.readline().rstrip())
rope = []
for _ in range(n):
    rope.append(int(sys.stdin.readline().rstrip()))


def solution(rope):
    return max([value * (index + 1) for index, value in enumerate(sorted(rope, reverse=True))])


print(solution(rope))

 

채점 결과