forked from nathan-abela/HackerRank-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03 - Greedy Florist.py
More file actions
47 lines (33 loc) · 900 Bytes
/
03 - Greedy Florist.py
File metadata and controls
47 lines (33 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# ========================
# Information
# ========================
# Direct Link: https://www.hackerrank.com/challenges/greedy-florist/problem
# Difficulty: Medium
# Max Score: 35
# Language: Python
# ========================
# Solution
# ========================
import os
# Complete the getMinimumCost function below.
def getMinimumCost(k, c):
sc = sorted(c, reverse=True)
s = 0
counter = 0
additional = 0
for c in sc:
if counter == k:
counter = 0
additional += 1
s += (additional + 1) * c
counter += 1
return s
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nk = input().split()
n = int(nk[0])
k = int(nk[1])
c = list(map(int, input().rstrip().split()))
MINIMUM_COST = getMinimumCost(k, c)
fptr.write(str(MINIMUM_COST) + '\n')
fptr.close()