Skip to content

Instantly share code, notes, and snippets.

View SudhagarS's full-sized avatar

Sudhagar SudhagarS

View GitHub Profile
def reduce(s):
global value, minimum
l = len(s)
minimum = l
if l == 1:
value = 1
return True
elif l == 2 and s[0] == s[1]:
value = 2
return True
line1=raw_input().split()
N,K,total,completed,Costs=int(line1[0]),int(line1[1]),0,0,[]
for n in raw_input().split():Costs.append(int(n))
Costs.sort(reverse=True)
friend=[0]*K
for i in range(N):
friend[completed%K]+=1
total=total+friend[completed%K]*Costs[i]
completed+=1
print total