#include using namespace std; typedef long long LL; const int MAXN = 1e6 + 10; const LL MOD = 1e9 + 7; const LL INF = 1e17; LL A[MAXN]; LL debot[MAXN]; LL ans[MAXN]; bool comp(pair a, pair b){ return a.first < b.first; } int main(){ int N, K; cin >> N >> K; for(int i = 1;i <= N;++i){ cin >> A[i]; } vector > heapK; vector > heap2K; ans[0] = INF; for(int i = 1;i <= N;++i){ while((!heapK.empty()) && heapK[0].second < i - K){ pop_heap(heapK.begin(), heapK.end(), comp); heapK.pop_back(); } while((!heap2K.empty()) && heap2K[0].second < (i - (2 * K + 1))){ pop_heap(heap2K.begin(), heap2K.end(), comp); heap2K.pop_back(); } debot[i] = A[i] + (i <= K + 1?0:heap2K[0].first); heapK.push_back(make_pair(debot[i], i)); heap2K.push_back(make_pair(debot[i], i)); push_heap(heap2K.begin(), heap2K.end(), comp); push_heap(heap2K.begin(), heap2K.end(), comp); ans[i] = heapK[0].first; ans[i] = min(ans[i], debot[i]); } cout << ans[N] << "\n"; return 0; }