We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def getMinimumCost(k, c):
c_len = len(c)
total = sum(c)
if k >= c_len:
return total
c_s = sorted(c, reverse=True)
total = sum(c_s[:k])
c_diff = c_s[k:]
i = 1
j = 1
for c_i in c_diff:
total += c_i * (1 + i)
if j < k:
j += 1
else:
i += 1
j = 1
return total
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Greedy Florist
You are viewing a single comment's thread. Return to all comments →
Less pythonic but my solution work too: