#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#define LL long long
using namespace std;
const int MAXN = 150000 + 10;
LL C[MAXN];
LL N, W, H;
int main()
{
while(scanf("%I64d%I64d%I64d", &N, &W, &H)!=EOF)
{
memset(C, 0, sizeof(C));
LL sum = 0;
for(int i=W+1;i<=W+N;i++)
{
scanf("%I64d", &C[i]);
sum += C[i];
}
if(sum < W * H)
{
printf("-1\n");
continue;
}
long long l = 0, r = 0;
for(int i=1;i<=W;i++)
{
l += H;
}
long long ans = l;
for(int i=2;i<=N+W+1;i++)
{
if(C[i-1] >= H) r -= (C[i-1] - H);
else l -= (H - C[i-1]);
if(C[i+W-1] >= H) r += (C[i+W-1] - H);
else l += (H - C[i+W-1]);
ans = min(ans, max(l, r));
}
printf("%I64d\n", ans);
}
return 0;
}
08-30
08-30