개발/알고리즘

BOJ (2217) - 로프 Python

Oreorobin 2021. 4. 28. 19:31

아이디어

  1. rope 리스트 큰 수 부터 정렬
  2. rope 리스트 값과 갯수만큼 다 곱한 결과가 제일 큰 값을 출력
10 17 13 8 20 21 11

1. 적용

21 20 17 13 11 10 8

2. 적용

21 40 51 52 55 60(max)
56

출력 : 60

 

소스코드

#https://www.acmicpc.net/problem/2217
import sys
input = sys.stdin.readline
N = int(input())
rope = []
for _ in range(N):
    rope.append(int(input()))

rope.sort(reverse = True)

for i in range(N):
    rope[i] = rope[i]*(i+1)

print(max(rope))