#include typedef struct { int key, id; } data; typedef struct { data obj[1000001]; int size; } min_heap; void push(min_heap* h, data x) { int i = ++(h->size), j = i >> 1; data tmp; h->obj[i] = x; while (j > 0) { if (h->obj[i].key < h->obj[j].key) { tmp = h->obj[j]; h->obj[j] = h->obj[i]; h->obj[i] = tmp; i = j; j >>= 1; } else break; } } data pop(min_heap* h) { int i = 1, j = 2; data output = h->obj[1], tmp; h->obj[1] = h->obj[(h->size)--]; while (j <= h->size) { if (j < h->size && h->obj[j^1].key < h->obj[j].key) j ^= 1; if (h->obj[j].key < h->obj[i].key) { tmp = h->obj[j]; h->obj[j] = h->obj[i]; h->obj[i] = tmp; i = j; j <<= 1; } else break; } return output; } void chmax(long long* a, long long b) { if (*a < b) *a = b; } int main() { int i, N, K, A[200001]; scanf("%d %d", &N, &K); for (i = 1; i <= N; i++) scanf("%d", &(A[i])); long long ans = 0, sum = 0; data d; min_heap h; h.size = 0; for (i = N; i >= 1; i--) { if (i % 2 == 0 && h.size == K - 1) chmax(&ans, A[i] + sum); if (h.size < K - 1) { d.key = A[i]; push(&h, d); sum += d.key; } else if (h.size > 0 && h.obj[1].key < A[i]) { d = pop(&h); sum -= d.key; d.key = A[i]; push(&h, d); sum += d.key; } } printf("%lld\n", ans); fflush(stdout); return 0; }