백준_2217_로프

임정민·2023년 6월 2일
1

알고리즘 문제풀이

목록 보기
55/173
post-thumbnail

백준 그리디 문제풀이 입니다.

문제

https://www.acmicpc.net/problem/2217

[나의 풀이]

N = int(input())
ropes = []

for i in range(N):
    ropes.append(int(input()))

ropes.sort()

max = 0

for i in range(len(ropes)):
    if max < ropes[i] * (len(ropes) - i):
        max = ropes[i] * (len(ropes) - i)
print(max)

여러 로프들의 조합으로 들 수 있는 최대 중량을 구하는 문제입니다. 그리디 알고리즘을 활용하여 간단히 해결할 수 있었습니다.🥝🥝🥝

저의 풀이 이외와 비슷한 방식으로

[다른 사람의 풀이]

n = int(input())
k = []
for _ in range(n):
    k.append(int(input()))
k.sort()

answers = []
for x in k:
    answers.append(x * n)
    n -= 1
print(max(answers))

위 와 같이 answers에 가능한 경우의 수를 모두 append해서 최대값을 출력한 풀이를 볼 수 있었습니다.🐌🐌🐌

감사합니다.

profile
https://github.com/min731

0개의 댓글