[Solution]
Binary find the max average value of the candies in float form. Each times you check, return the first segment whose sum is over zero to make the answer a fraction.
[Code]
#include <cstdio>
#include <cmath>
#include <memory.h>
#include <algorithm>
using namespace std;
typedef long long qw;
typedef long double exf;
typedef pair <int, int> dpair;
#ifdef WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif
const int maxn = 200009;
const exf eps = 1e-10;
int n, d, u, a[maxn];
int qe[maxn], qo[maxn], eh, et, oh, ot;
exf s[maxn];
void inq(int x) {
if (x & 1) {
while (oh < ot && s[x] < s[qo[ot - 1]])
-- ot;
qo[ot ++] = x;
}
else {
while (eh < et && s[x] < s[qe[et - 1]])
-- et;
qe[et ++] = x;
}
}
dpair check(exf v) {
eh = 0, et = 0;
oh = 0, ot = 0;
s[0] = 0;
for (int i = 1; i <= n; ++ i) {
s[i] = s[i - 1] + a[i] - v;
if (i & 1) {
while (i - qo[oh] > u && oh < ot)
++ oh;
if (oh < ot && s[i] - s[qo[oh]] >= 0)
return dpair(qo[oh], i);
}
else {
while (i - qe[eh] > u && eh < et)
++ eh;
if (eh < et && s[i] - s[qe[eh]] >= 0)
return dpair(qe[eh], i);
}
if (i - d + 1 >= 0)
inq(i - d + 1);
}
return dpair(-1, -1);
}
inline qw gcd(qw a, qw b) {
return (b % a) ? gcd(b % a, a) : a;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
scanf("%d%d%d", &n, &d, &u);
for (int i = 1; i <= n; ++ i)
scanf("%d", a + i), a[i + n] = a[i];
n *= 2;
exf l = 0, r = 1e9;
dpair s;
while (r - l > eps) {
exf mid = (l + r) / 2.0;
s = check(mid);
if (s. first > -1)
l = mid;
else
r = mid;
}
qw t = 0, c;
s = check(l);
c = s. second - s. first;
for (int i = s. first + 1; i <= s. second; ++ i)
t += a[i];
qw g = gcd(t, c);
t /= g;
c /= g;
if (c == 1)
printf(lld "\n", t);
else
printf(lld "/" lld "\n", t, c);
}