프로그래밍/코딩테스트 알고리즘
[greedy] 큰 수의 법칙
Leeys
2022. 3. 19. 22:17
반응형
1. 내 정답
import time
times = time.time()
n, m ,k = list(map(int, input().split()))
data = list(map(int, input().split()))
data.sort()
print(data)
first = data[n-1]
print(first)
second = data[n-2]
print(second)
count = 0
while True:
for i in range(k):
if m != 0:
count += first
m -= 1
if m != 0:
count += second
m-= 1
if m == 0:
break
timese = time.time()
print('시간 :', timese - times)
print(count)
2. 원래 답
import time
times = time.time()
n, m, k = list(map(int, input().split()))
data = list(map(int, input().split()))
data.sort()
first = data[n-1]
second = data[n-2]
count = int(m / (k+1)) * k
count += m% (k+1)
result = 0
result += (count) * first
result += (m - count) * second
timese = time.time()
print('시간 :', timese - times)
print(result)
반응형