#include <iostream>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const int MAXN = 200 * 1000 + 123;
ll a[MAXN];
bitset<MAXN> mark;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
ll n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
deque<pll> d;
ll cur = 0, ans = 0;
for (int i = 0; i < n + m; i++) {
d.push_back({i, a[i]});
while (!d.empty() && d.front().first <= i - m) {
//ans += a[d.front().first] - d.front().second;
//cerr << d.front().first << ' ' << a[d.front().first] - d.front().second << endl;
cur -= a[d.front().first] - d.front().second;
d.pop_front();
}
if (mark[i - m]) {
cur -= a[i - m];
}
//cout << "curd8 " << i << ' ' << cur << endl;
while (cur < k && !d.empty()) {
if (d.back().second + cur <= k) {
cur += d.back().second;
ans += d.back().second;//a[d.back().first];
mark[d.back().first] = true;
//cerr << "yo " << d.back().first - m << ' ' << a[d.back().first] << endl;
d.pop_back();
} else {
d.back().second -= (k - cur);
ans += (k - cur);
cur = k;
}
}
//cout << "curd " << i << ' ' << cur << endl;
}
cout << ans;
return 0;
}