import heapq def main(): import sys input = sys.stdin.read data = input().split() N = int(data[0]) K = int(data[1]) A = list(map(int, data[2:2+N])) current = A.copy() heap = [] for i in range(1, N+1): if i % 2 == 0: heapq.heappush(heap, (-current[i-1], i-1)) # Using max-heap by negating sum_k = 0 for _ in range(K): if not heap: break val, idx = heapq.heappop(heap) val = -val sum_k += val # Now, update all elements after idx for j in range(idx+1, N): current[j-1] = current[j] current.pop() N -= 1 # Add new even positions new_heap = [] for i in range(1, N+1): if i % 2 == 0: pos = i-1 if pos >= len(current): continue heapq.heappush(new_heap, (-current[pos], pos)) heap = new_heap print(sum_k) if __name__ == "__main__": main()