// Задача "Герой гитары"
// 7-ая Личная интернет-олимпиада сезона 2008-2009
// Автор задачи: Антон Ахи
// Автор решения: Сергей Мельников, melnikov@rain.ifmo.ru
// неверное решение: жадность, ботва с отрицательными
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;

public class guitar_sm_wrong1 extends Thread {

	class Note implements Comparable<Note> {
		int cost;
		int pos;

		public Note(int pos, int cost) {
			this.pos = pos;
			this.cost = cost;
		}

		public int compareTo(Note o) {
			if (cost > o.cost)
				return -1;
			if (cost < o.cost)
				return 1;
			return 0;
		}
	}

	void solve() throws IOException {
		int n = nextInt();
		myAssert(1 <= n && n <= 10000);
		int k = nextInt();
		myAssert(1 <= k && k <= 1000);
		int a[] = new int[n];
		Note[] ns = new Note[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = nextInt();
			myAssert(-1e9 <= a[i] && a[i] <= 1e9);
			ns[i] = new Note(i, a[i]);
		}
		Arrays.sort(ns);
		boolean u[] = new boolean[n];
		long ans = 0;
		for (int it = 0; it < a.length; it++) {
			int i = ns[it].pos;
			int okl = k + 1;
			for (int j = 1; j <= k; j++) {
				if (i - j < 0 || !u[i - j]) {
					okl = j - 1;
					break;
				}
			}
			int okr = k + 1;
			for (int j = 1; j <= k; j++) {
				if (i + j >= u.length || !u[i + j]) {
					okr = j - 1;
					break;
				}
			}
			if (okl + okr + 1 <= k) {
				u[i] = true;
				ans += ns[it].cost;
			}
		}
		out.println(ans);
	}

	void myAssert(boolean b) {
		if (!b)
			throw new AssertionError();
	}

	StreamTokenizer st;
	PrintWriter out;

	int nextInt() {
		try {
			st.nextToken();
		} catch (IOException e) {
			return -1;
		}
		return (int) st.nval;
	}

	public void run() {
		try {
			st = new StreamTokenizer(new FileReader("guitar.in"));
			out = new PrintWriter(new BufferedWriter(new FileWriter(
					"guitar.out")));
			solve();
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public static void main(String[] args) {
		new guitar_sm_wrong1().start();
	}

}
