Skip to content

Instantly share code, notes, and snippets.

@SudhagarS
Created October 30, 2012 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SudhagarS/3982401 to your computer and use it in GitHub Desktop.
Save SudhagarS/3982401 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment