Python Algorithms - Greedy - "law of great numbers"

Sunmi Shin·2022년 11월 5일

Python Algorithms

목록 보기
3/7
post-thumbnail

Problem:
Get the greatest sum of numbers by adding given N numbers M times. But, the greatest number, among the numbers, can be added not over K times in a row.
큰 수의 법칙에 따라 가장 큰 수의 합을 구해라.

#input (ex: 5 8 3, 2 4 5 4 6)
n, m, k = map(int, input().split())
data = list(map(int, input().split()))

#Get the greatest number and the second greatest number
first = max(data)
data.remove(first)
second = max(data)

#Initialize the result
result = 0

# sum = (2) * (3) * 6 + (2) * 5  
result = (m//k) * k * first + (m%k) * second

print(result)
profile
Tempest Data Analyst

0개의 댓글