#include<bits/stdc++.h>
using namespace std;
int n, m, k, a[1000005];
long long pre[1000005];
int main() {
cin >> m >> n >> k;
for (int i = 1; i <= m; i++)
cin >> a[i];
sort(a + 1, a + m + 1);
for (int i = 1; i <= m; i++)
pre[i] = pre[i - 1] + a[i];
long long Ans = -2;
for (int i = n; i <= m; i++) {
/// goi ban thu i la cao nhat
/// (i - 1, i - 2, i - 3, ... sao cho du n thang
/// (i - n + 1)
/// tap the cac ban [i - n + 1, i]
if (a[i] - a[i - n + 1] <= k)
Ans = max(Ans, pre[i] - pre[i - n]);
}
cout << Ans;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbiwgbSwgaywgYVsxMDAwMDA1XTsKbG9uZyBsb25nIHByZVsxMDAwMDA1XTsKCmludCBtYWluKCkgewogICAgY2luID4+IG0gPj4gbiA+PiBrOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbTsgaSsrKQogICAgICAgIGNpbiA+PiBhW2ldOwogICAgc29ydChhICsgMSwgYSArIG0gKyAxKTsKICAgIAogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbTsgaSsrKQogICAgICAgIHByZVtpXSA9IHByZVtpIC0gMV0gKyBhW2ldOwogICAgCiAgICBsb25nIGxvbmcgQW5zID0gLTI7CgogICAgZm9yIChpbnQgaSA9IG47IGkgPD0gbTsgaSsrKSB7CiAgICAgICAgLy8vIGdvaSBiYW4gdGh1IGkgbGEgY2FvIG5oYXQKICAgICAgICAvLy8gKGkgLSAxLCBpIC0gMiwgaSAtIDMsIC4uLiBzYW8gY2hvIGR1IG4gdGhhbmcKICAgICAgICAvLy8gKGkgLSBuICsgMSkKICAgICAgICAvLy8gdGFwIHRoZSBjYWMgYmFuIFtpIC0gbiArIDEsIGldCiAgICAgICAgaWYgKGFbaV0gLSBhW2kgLSBuICsgMV0gPD0gaykKICAgICAgICAgICAgIEFucyA9IG1heChBbnMsIHByZVtpXSAtIHByZVtpIC0gbl0pOwogICAgfQogICAgY291dCA8PCBBbnM7Cgp9Cg==