import java.io.*; import java.util.*; public class Solution { static Map> map = new HashMap<>(); static long cost(long[] c, int n, int k, int start, int end) { if (map.containsKey(start)) { if (map.get(start).containsKey(end)) { return map.get(start).get(end); } } else { map.put(start, new HashMap()); } long cost = Long.MAX_VALUE; if (end - start <= k) { for (int i = start; i <= end; i++) { cost = Math.min(cost, c[i]); } } else { for (int i = Math.max(0, start - k); i <= Math.min(n-1, end + k - 1); i++) { //System.out.println(start + " " + end + " " + (end - start)); long nc = c[i]; if (i - k > start) { //System.out.println(i + " " + "start"); nc += cost(c, n, k, start, i - k); } if (i + k < end) { //System.out.println(i + " " + "end"); nc += cost(c, n, k, i + k + 1, end); } cost = Math.min(cost, nc); } } map.get(start).put(end, cost); return cost; } public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); long[] c = new long[n]; for (int i = 0; i < n; i++) { c[i] = sc.nextLong(); } System.out.println(cost(c, n, k, 0, n-1)); } }