#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <typename T>   using v = vector<T>;   const long long mod1 = 1e9 + 7;   const long long mod2 = 36028797018963913;   const long long inf = 2e18;   void read() {}   void print() {}   void debug() { cerr << endl; }   long long gcd(long long a, long long b) {     if (a > b) swap(a, b);     if (a) return gcd(a, b % a);     return b;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   struct vt {     long long x, y;     vt operator-() { return vt(-this->x, -this->y); }     vt operator+(vt b) { return {this->x + b.x, this->y + b.y}; }     vt operator-(vt b) { return *this + (-b); }     vt operator*(long long b) { return vt(this->x * b, this->y * b); }     long long operator*(vt b) { return this->x * b.x + this->y * b.y; }     vt operator/(long long b) { return vt(this->x / b, this->y / b); }     long long operator%(vt b) { return this->x * b.y - b.x * this->y; }     bool operator==(vt b) { return this->x == b.x && this->y == b.y; }     bool operator!=(vt b) { return !((*this) == b); }     bool collinear(vt b) { return (*this) % b == 0; }     bool opposite(vt b) { return this->collinear(b) && (*this) * b < 0; }     double length() { return sqrt(this->x * this->x + this->y * this->y); }     long long sqLength() { return this->x * this->x + this->y * this->y; }     vt() {}     vt(long long x, long long y) : x(x), y(y) {}     vt(long long x1, long long y1, long long x2, long long y2)         : x(x2 - x1), y(y2 - y1) {}   };   long long fact(long long a, long long mod) {     if (a == 1)       return 1;     else       return (a * fact(a - 1, mod)) % mod;   }   long long sign(long long a) {     if (a > 0) return 1;     if (a == 0) return 0;     return -1;   }   bool prime(long long a) {     if (a < 2) return 0;     if (a == 2) return 1;     for (long long b = 2; b <= ceil(sqrt(a)); b++)       if (a % b == 0) return 0;     return 1;   }   long long pow(long long a, long long b, long long mod) {     if (b == 0) return 1;     if (b == 1) return a;     long long res = pow(a, b / 2, mod);     res = (res * res) % mod;     if (b % 2) return (a * res) % mod;     return res;   }   long long hashStr(string& s) {     long long base = 26;     long long res = 0;     for (long long i = 0; i < ((long long)(s).size()); i++)       res = ((res * base) % mod2 + s[i] -  a  + 1) % mod2;     return (res + mod2) % mod2;   }   long long hashStr(long long prevHash, char curChar) {     return ((prevHash * 26) % mod2 + curChar -  a  + 1) % mod2;   }   struct node {     node *left = nullptr, *right = nullptr;     long long w, val, sz = 1;     node(long long val) : w((rand() << 16) + rand()), val(val) {}   };   long long siz(node* a) {     if (a == nullptr)       return 0;     else       return a->sz;   }   node* treap;   node* merge1(node* v1, node* v2) {     if (v1 == nullptr) return v2;     if (v2 == nullptr) return v1;     if (v1->w > v2->w) {       v1->right = merge1(v1->right, v2);       v1->sz = siz(v1->left) + siz(v1->right) + 1;       return v1;     } else {       v2->left = merge1(v1, v2->left);       v2->sz = siz(v2->left) + siz(v2->right) + 1;       return v2;     }   }   pair<node*, node*> split(node* w, long long k) {     if (w == nullptr) return {nullptr, nullptr};     if (siz(w->left) >= k) {       auto tmp = split(w->left, k);       w->left = tmp.second;       w->sz = siz(w->left) + siz(w->right) + 1;       return {tmp.first, w};     } else {       auto tmp = split(w->right, k - siz(w->left) - 1);       w->right = tmp.first;       w->sz = siz(w->left) + siz(w->right) + 1;       return {w, tmp.second};     }   }   ifstream fin( input.txt );   ofstream fout( output.txt );   template <typename Arg, typename... Args>   void read(Arg& arg, Args&... args) {     cin >> (arg);     read(args...);   }   template <typename Arg, typename... Args>   void print(Arg arg, Args... args) {     cout << (arg) <<    ;     print(args...);   }   template <typename Arg, typename... Args>   void debug(Arg arg, Args... args) {     cerr << (arg) <<    ;     debug(args...);   }   void prnt(node* a) {     if (a == nullptr) return;     prnt(a->left);     print(a->val);     prnt(a->right);   }   long long getInt() {     long long a;     cin >> a;     return a;   }   void run() {     long long w, d;     read(w, d);     long long a[w + 1];     for (long long i = (0); i < (w - 1); i++) cin >> a[i + 1];     a[w] = 1e9;     long long dp[w + 1];     dp[0] = 1e9;     a[0] = 1e9;     long long l = 0;     set<long long> p;     p.insert(0);     for (long long i = (1); i < (w + 1); i++) {       dp[i] = 0;       l = max(i - d, l);       while ((*p.begin()) < l) p.erase(*p.begin());       while (!p.empty()) {         long long cur = *p.begin();         if (dp[cur] <= a[i] - dp[i]) {           dp[i] += dp[cur];           dp[cur] = 0;           p.erase(cur);         } else {           long long mn = a[i] - dp[i];           dp[i] = a[i];           dp[cur] -= mn;           break;         }       }       if (dp[i]) p.insert(i);     }     cout << dp[w];   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     run();     return 0;   }