#include<cstdio>
#include<cctype>
#include<queue>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c==‘-‘) f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-‘0‘;
return x*f;
}
typedef long long ll;
const int maxn=100010;
const int maxnode=2000010;
int n,S,d,A[maxn],tmp[maxn];
ll sumv[maxnode];
int root[maxn],s[maxnode],ls[maxnode],rs[maxnode],ToT;
void build(int& y,int x,int l,int r,int p) {
s[y=++ToT]=s[x]+1;sumv[y]=sumv[x]+tmp[p];if(l==r) return;
int mid=l+r>>1;ls[y]=ls[x];rs[y]=rs[x];
if(p<=mid) build(ls[y],ls[x],l,mid,p);
else build(rs[y],rs[x],mid+1,r,p);
}
ll query(int y,int x,int l,int r,int k) {
if(l==r) return (ll)min(s[y]-s[x],k)*tmp[l];
int mid=l+r>>1;
if(s[rs[y]]-s[rs[x]]>=k) return query(rs[y],rs[x],mid+1,r,k);
return query(ls[y],ls[x],l,mid,k-s[rs[y]]+s[rs[x]])+sumv[rs[y]]-sumv[rs[x]];
}
ll solve(int l,int r) {
int w=r-l+min(r-S,S-l);
if(d<=w) return 0;
return query(root[r],root[l-1],1,n,min(r-l+1,d-w));
}
int calc(int x,int y) {
int l=S,r=n+1;
while(l<r) {
int mid=l+r>>1;
if(solve(x,mid)<=solve(y,mid)) r=mid;
else l=mid+1;
}
return l;
}
int Q[maxn],g[maxn];
int main() {
n=read();S=read()+1;d=read();
rep(i,1,n) A[i]=tmp[i]=read();
sort(tmp+1,tmp+n+1);
rep(i,1,n) A[i]=lower_bound(tmp+1,tmp+n+1,A[i])-tmp;
rep(i,1,n) build(root[i],root[i-1],1,n,A[i]);
int l=1,r=0;
rep(i,1,S) {
while(l<r&&g[r-1]>=calc(Q[r],i)) r--;
Q[++r]=i;if(l<r) g[r-1]=calc(Q[r-1],Q[r]);
}
ll ans=0;
rep(i,S,n) {
while(l<r&&solve(Q[l],i)<=solve(Q[l+1],i)) l++;
ans=max(ans,solve(Q[l],i));
}
printf("%lld\n",ans);
return 0;
}