n, k = map(int, input().split()) arr = list(map(int, input().split())) # Sort the array by value, keeping track of their 1-based indices sorted_arr = sorted([(a, i+1) for i, a in enumerate(arr)], key=lambda x: x[0]) m = n // k sum_ans = 0 ptr = len(sorted_arr) - 1 # Starting from the end of the sorted array for i in range(1, m + 1): required_pos = n - (i * k) + 1 while ptr >= 0: if sorted_arr[ptr][1] >= required_pos: sum_ans += sorted_arr[ptr][0] ptr -= 1 break else: ptr -= 1 print(sum_ans)