using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemSolver { class Solution { static char[] splitors = { ' ' }; /* Input data here */ static int n; static int k; static long[] c; static void Input() { string[] str = Console.ReadLine().Split(splitors); n = int.Parse(str[0]); k = int.Parse(str[1]); str = Console.ReadLine().Split(splitors); c = new long[n]; for (int i = 0; i < n; i++) { c[i] = long.Parse(str[i]); } } static void Search() { long[] cost = new long[n]; for (int i = 0; i < n; i++) { cost[i] = -1; } cost[n - 1] = 0; for (int i = n - 2; i >= 0; i--) { int next = i + k + 1; if (next < n) { int j = Math.Min(next + k, n - 1); // for (int j = i + 1; j <= next + k && j < n; j++) if (cost[j] != -1) { if (cost[i] == -1) { cost[i] = cost[j] + c[next]; } else { cost[i] = Math.Min(cost[i], cost[j] + c[next]); } } } } long ret = -1; for (int last = 0; last <= k && last < n; last++) { int j = Math.Min(last + k, n - 1); //for (int j = 0; j <= last + k && j < n; j++) if (cost[j] != -1) { long val = cost[j] + c[last]; if (ret == -1) { ret = val; } else { ret = Math.Min(ret, val); } } } Console.WriteLine(ret); } static void Main(string[] args) { Input(); Search(); } } }