from heapq import heappush, heappop
n, r = map(int, input().split())
times = list(map(int, input().split()))
times.sort()
heap = [0] * r
res = 0
for x in times:
time = heappop(heap)
time += x
res += time
heappush(heap, time)
print(res)



京公网安备 11010502036488号