#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 2e5 + 100;

ll n,m,d;
ll arr[maxn];

ll a1[maxn] , id1;
ll a2[maxn] , id2;

multiset<ll> sl,ss;
int main()
{

	cin >> n >> d >> m;

	ll ans = 0;
	ll sum = 0;

	int pp = 0;

	repn(i,n) {
		cin >> arr[i];
		if(arr[i] <= m){
			sum += arr[i];
			a1[id1++] = arr[i];
		}
		else a2[id2++] = arr[i];
	}
	sort(a1,a1+id1);
	sort(a2,a2+id2);reverse(a2,a2+id2);

	int it1 = 0 , it2 = id2 - 1;

	while(it1 != it2){

		bool flag = 0;
		sum += a2[it1];

		it1++;
		for (int i = 1 ; i <= d ; ++i){
			if(it1==it2){
				flag = 1;
				break;
			}
			it2--;

		}
		ans = max(ans,sum);
		if(flag) break;
		//ans = max(ans,sum);
	}

	int it3 = 0;

	while(it1 != id2){
		int cnt = 0;
		bool flag = 1;
		ll val = 0;

		for (int i = 1 ; i <= d ; ++i){
			if(it3 == id1){
				flag=0;
				break;
			} else {

				val += a1[it3];
				it3++;
			}
		}

		if(!flag) break;
		if(val < a2[it1]){
			sum -= val;
			sum += a2[it1];
			it1++;
			ans = max(ans,sum);
		} else break;
		ans = max(ans,sum);
	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 2e5 + 100;

ll n,m,d;
ll arr[maxn];

ll a1[maxn] , id1;
ll a2[maxn] , id2;

multiset<ll> sl,ss;
int main()
{

	cin >> n >> d >> m;

	ll ans = 0;
	ll sum = 0;

	int pp = 0;

	repn(i,n) {
		cin >> arr[i];
		if(arr[i] <= m){
			sum += arr[i];
			a1[id1++] = arr[i];
		}
		else a2[id2++] = arr[i];
	}
		sort(arr+1,arr+1+n);reverse(arr+1,arr+1+n);
//	repn(i,n) cout << arr[i] << ' ';
//	cout << endl;
	ans = sum;
	sort(a1,a1+id1);
	sort(a2,a2+id2);reverse(a2,a2+id2);

	int it1 = 0 , it2 = id2 - 1;

	while(it1 <= it2){

		pp = d + 1;
		bool flag = 0;
		sum += a2[it1];
		ans = max(ans,sum);
		pp -= (it2 -it1);
		if(it2 - it1 > d){
			it1++;
			it2-= d;

		} else{
			it1++;
			break;
		}

		ans = max(ans,sum);

		if(flag) break;
		//ans = max(ans,sum);
	}

	int it3 = 0;

	while(it1 <= id2){
		int cnt = 0;
		bool flag = 1;
		ll val = 0;

		for (int i = 1 ; i <= pp ; ++i){
			if(it3 == id1){
				flag=0;
				break;
			} else {

				val += a1[it3];
				it3++;
			}
		}
		pp = d+1;

		if(!flag) break;
		if(val < a2[it1]){
			sum -= val;
			sum += a2[it1];
			it1++;
			ans = max(ans,sum);
		} else break;
		ans = max(ans,sum);
	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 2e5 + 100;
ll arr[maxn];
ll pre[maxn];
ll n,m,d;

int main()
{

	cin >> n >> d >> m;

	repn(i,n) cin >> arr[i];

	sort(arr+1,arr+n+1);
	reverse(arr+1,arr+n+1);

	int head = 1 , tail = n;

	ll ans = 0;
	ll sum = 0;

	repn(i,n){
		if(arr[i] <= m) {
			sum += arr[i];
		}
	}
	ans = max(sum,ans);

	bool fst = 1;
	while(arr[head] > m){
		if(fst){
			fst = 0;
			sum += arr[head];
			ans = max(sum,ans);
		} else {
			sum += arr[head];

			if(head + d >= tail) {
				ans = max(sum,ans);
				break;
			}
			for (int p = 1 ; p <= d ; ++p)
				sum -= arr[tail--];
			ans = max(sum,ans);

		}

		head++;
	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 2e5 + 100;

ll n,m,d;
ll arr[maxn];

ll a1[maxn] , id1;
ll a2[maxn] , id2;

multiset<ll> sl,ss;
int main()
{

	cin >> n >> d >> m;

	ll ans = 0;
	ll sum = 0;

	int pp = 0;

	repn(i,n) {
		cin >> arr[i];
		if(arr[i] <= m){
			sum += arr[i];
			a1[id1++] = arr[i];
		}
		else a2[id2++] = arr[i];
	}
	ans = sum;
	sort(a1,a1+id1);
	sort(a2,a2+id2);reverse(a2,a2+id2);

	int it1 = 0 , it2 = id2 - 1;

	while(it1 <= it2){

		bool flag = 0;
		sum += a2[it1];

		it1++;
		for (int i = 1 ; i <= d ; ++i){
			if(it1==it2){
				flag = 1;
				break;
			}
			it2--;

		}
		ans = max(ans,sum);
		if(flag) break;
		//ans = max(ans,sum);
	}

	int it3 = 0;

	while(it1 <= id2){
		int cnt = 0;
		bool flag = 1;
		ll val = 0;

		for (int i = 1 ; i <= d ; ++i){
			if(it3 == id1){
				flag=0;
				break;
			} else {

				val += a1[it3];
				it3++;
			}
		}

		if(!flag) break;
		if(val < a2[it1]){
			sum -= val;
			sum += a2[it1];
			it1++;
			ans = max(ans,sum);
		} else break;
		ans = max(ans,sum);
	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 1e5 + 100;
ll arr[maxn];
ll pre[maxn];
ll n,m,d;

int main()
{

	cin >> n >> d >> m;

	repn(i,n) cin >> arr[i];

	sort(arr+1,arr+n+1);
	reverse(arr+1,arr+n+1);

	int id = 0;
	repn(i,n){
		if(arr[i] <= m) {
			id++;
			pre[id] += pre[id-1];
			pre[id] += arr[i];
		}
	}

	ll ans = pre[id];

	ll sum = 0;

	int k = id;

	repn(i,n){
		if(arr[i] <= m) break;

		if(id>0){
			sum += arr[i];
			ll tmp = sum + pre[id];
			ans = max(tmp,ans);
		} else {
			sum += arr[i];
			n -= d;
			ans = max(sum,ans);
		}
		id -= d;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 2e5 + 100;
ll arr[maxn];
ll pre[maxn];
ll n,m,d;

int main()
{

	cin >> n >> d >> m;

	repn(i,n) cin >> arr[i];

	sort(arr+1,arr+n+1);
	reverse(arr+1,arr+n+1);

	int head = 1 , tail = n;

	ll ans = 0;
	ll sum = 0;

	int total = 0;

	repn(i,n){
		if(arr[i] <= m) {
			sum += arr[i];
		}
	}
	ans = max(sum,ans);

	bool fst = 1;

	while(arr[head] > m){
		if(fst){
			fst = 0;
			sum += arr[head];
			ans = max(sum,ans);
			total++;

		} else {
			sum += arr[head];
			total++;
			for (int p = 1 ; p <= d && total <= n ; ++p, ++total){
				sum -= arr[tail--];
			}

			ans = max(sum,ans);
		}
		head++;

	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 2e5 + 100;
ll arr[maxn];
ll pre[maxn];
bool inq[maxn];
ll n,m,d;

int main()
{

	cin >> n >> d >> m;

	repn(i,n) cin >> arr[i];

	sort(arr+1,arr+n+1);
	reverse(arr+1,arr+n+1);

	int head = 1 , tail = n;

	ll ans = 0;
	ll sum = 0;

	int total = 0;

	repn(i,n){
		if(arr[i] <= m) {
			sum += arr[i];
			inq[i] = 1;
		}
	}
	ans = max(sum,ans);

	bool fst = 1;

	while(arr[head] > m && head < tail && 	total < n){
		if(fst){
			fst = 0;
			sum += arr[head];
			ans = max(sum,ans);
			total++;

		} else {

			for (int p = 1 ; p <= d && total <= n ; ++p, ++total){
				if(inq[tail])
					sum -= arr[tail];
				tail--;
			}
			if(head <= tail){

			sum += arr[head];
			total++;

			ans = max(sum,ans);}
			else break;
		}
		head++;

	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 2e5 + 100;
ll arr[maxn];
ll pre[maxn];
ll n,m,d;

int main()
{

	cin >> n >> d >> m;

	repn(i,n) cin >> arr[i];

	sort(arr+1,arr+n+1);
	reverse(arr+1,arr+n+1);

	int head = 1 , tail = n;

	ll ans = 0;
	ll sum = 0;

	repn(i,n){
		if(arr[i] <= m) {
			sum += arr[i];
		}
	}
	ans = max(sum,ans);

	bool fst = 1;
	while(arr[head] > m){
		if(fst){
			fst = 0;
			sum += arr[head];
			head++;
			ans = max(sum,ans);

		} else {
			sum += arr[head];
			head++;
			for (int p = 1 ; p <= d ; ++p)
			{
				if(tail-1 == head) break;
				sum -= arr[tail];
				tail--;

			}
			ans = max(sum,ans);
			if(tail == head) break;

		}

	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 2e5 + 100;

ll n,m,d;
ll arr[maxn];
multiset<ll> sl,ss;
int main()
{

	cin >> n >> d >> m;

	ll ans = 0;
	ll sum = 0;

	int pp = 0;

	repn(i,n) {
		cin >> arr[i];
		if(arr[i] <= m){
			sum += arr[i];
			ss.insert(arr[i]);
		}
		else sl.insert(arr[i]);
	}
	auto it1 = sl.rbegin();
	auto it2 = sl.rend(); it2--;

	while(it1 != it2){

		bool flag = 0;
		sum += *it1;
		it1++;
		for (int i = 1 ; i <= d ; ++i){
			if(it1==it2){
				pp--;
				flag = 1;
				break;
			}
			it2--;

		}
		ans = max(ans,sum);
		if(flag) break;
		//ans = max(ans,sum);
	}

	auto it3 = ss.begin();

	while(it1 != sl.rend()){
		int cnt = 0;
		bool flag = 1;
		ll val = 0;

		for (int i = 1 ; i <= d ; ++i){
			if(it3 == ss.end()){
				flag=0;
				break;
			} else {

				val += *it3;
				it3++;
			}
		}
		pp = d+1;

		if(!flag) break;
		if(val < *it1){
			sum -= val;
			sum += *it1;
			it1++;
			ans = max(ans,sum);
		} else break;
		ans = max(ans,sum);
	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 2e5 + 100;
ll arr[maxn];
ll pre[maxn];
bool inq[maxn];
ll n,m,d;

int main()
{

	cin >> n >> d >> m;

	repn(i,n) cin >> arr[i];

	sort(arr+1,arr+n+1);
	reverse(arr+1,arr+n+1);

	int head = 1 , tail = n;

	ll ans = 0;
	ll sum = 0;

	int total = 0;

	repn(i,n){
		if(arr[i] <= m) {
			sum += arr[i];
			inq[i] = 1;
		}
	}
	ans = max(sum,ans);

	bool fst = 1;

	while(arr[head] > m && head < tail && 	total < n){
		if(fst){
			fst = 0;
			sum += arr[head];
			ans = max(sum,ans);
			total++;

		} else {

			for (int p = 1 ; p <= d && total <= n ; ++p, ++total){
				if(inq[tail])
					sum -= arr[tail];
				total++;
				tail--;
			}
			if(head <= tail){

			sum += arr[head];
			total++;

			ans = max(sum,ans);}
			else break;
		}
		head++;

	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0 ; i < (n) ; ++i)
#define repn(i,n) for (int i = 1; i <= (n) ; ++i)
#define rep2(i,j,n) for (int i = (j) ; i < (n) ; ++i)
#define repn2(i,j,n) for (int i = (j); i <= (n) ; ++i)
#define debug(x) printf("%s = %d\n",#x,x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;

ll qpow(ll a , ll exp ,ll mod = mod){ ll res = 1; while(exp){ if(exp & 1) res = res * a % mod; a = a * a % mod; exp >>= 1;} return res; }
ll inv(ll num , ll mod = mod){ return qpow(num,mod-2);}

struct Moder{
	template<typename T> static T add(const T & a ,const T& b){ return ((a+b) % mod + mod) % mod;}
	template<typename T> static T mul(const T & a ,const T& b){ return ((a-b) % mod + mod) % mod;}
	template<typename T> static T get(const T & a){ return (a % mod + mod) % mod;}
};
struct FIO{ // char*s, int
    int c,f,e;  operator int() { return ~e; }
    FIO& operator >> (char* s){e=scanf("%s",s);return *this;}
    template<class T>FIO& operator >> (T& x){
        for(f=0;~c&&(c<48||c>57);c=getchar()){if(c=='-')f=1;}
        for(x=0,e=c;c>47 && c<58;c=getchar()){x=x*10+(c^48);}
        if(f) {x=-x;}   return *this;}
};
const int maxn = 2e5 + 100;
ll arr[maxn];
ll pre[maxn];
ll n,m,d;

int main()
{

	cin >> n >> d >> m;

	repn(i,n) cin >> arr[i];

	sort(arr+1,arr+n+1);
	reverse(arr+1,arr+n+1);

	int id = 0;
	repn(i,n){
		if(arr[i] <= m) {
			id++;
			pre[id] += pre[id-1];
			pre[id] += arr[i];
		}
	}

	ll ans = pre[id];

	ll sum = 0;

	repn(i,n){
		if(arr[i] <= m) break;

		if(id>0){
			sum += arr[i];
			ll tmp = sum + pre[id];
			ans = max(tmp,ans);
			id -= d;
			n -= d;
		} else {
			sum += arr[i];
			n -= d;
			ans = max(sum,ans);
		}

	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long double ld;                                   // XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9+7;
const int INF = 1e18;
const int maxn = 2e5+5;

void solve(){
	int n, d, m; cin>>n>>d>>m;
	vector <int> a, b;
	rep(i, 0, n){
		int x; cin>>x;
		if(x > m) b.PB(x);
		else a.PB(x);
	}
	sort(all(a)); reverse(all(a));
	sort(all(b)); reverse(all(b));
	int st[n+5] = {};
	rep(i, 0, sz(a))
		st[i+1] = st[i] + a[i];
	int k = sz(b), big = 0, ans = st[sz(a)+1];
	if(k) ans += b[0];
	rep1(i, 1, k){
		big += b[i-1];
		int req = max(0ll , (i-1)*d - (k - i));
		if(req > sz(a)) break;
		int small = st[sz(a) - req];
		ans = max(ans, small + big);
	}
	cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //io();
    cout<<setprecision(16);

    int tc=1;// cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long double ld;                                   // XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9+7;
const int INF = 1e18;
const int maxn = 2e5+5;

void solve(){
	int n, d, m; cin>>n>>d>>m;
	vector <int> a, b;
	rep(i, 0, n){
		int x; cin>>x;
		if(x > m) b.PB(x);
		else a.PB(x);
	}
	sort(all(a)); reverse(all(a));
	sort(all(b)); reverse(all(b));
	int st[n+5] = {};
	rep(i, 0, sz(a))
		st[i+1] = st[i] + a[i];
	int k = sz(b), big = 0, ans = st[sz(a)];
	rep1(i, 1, k){
		big += b[i-1];
		int req = max(0ll , (i-1)*d - (k - i));
		if(req > sz(a)) break;
		int small = st[sz(a) - req];
		ans = max(ans, small + big);
	}
	cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //io();
    cout<<setprecision(16);

    int tc=1;// cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long double ld;                                   // XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9+7;
const int INF = 1e18;
const int maxn = 2e5+5;

void solve(){
	int n, d, m; cin>>n>>d>>m;
	vector <int> a, b;
	rep(i, 0, n){
		int x; cin>>x;
		if(x > m) b.PB(x);
		else a.PB(x);
	}
	sort(all(a)); reverse(all(a));
	sort(all(b)); reverse(all(b));
	int st[n+5] = {};
	rep(i, 0, sz(a))
		st[i+1] = st[i] + a[i];
	int k = sz(b), big = 0, ans = 0;
	rep(i, 0, k){
		big += b[i];
		int req = max(0ll , i*(d+1)-k+1);
		if(req > sz(a)) break;
		int small = st[sz(a) - req];
		ans = max(ans, small + big);
	}
	cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //io();
    cout<<setprecision(16);

    int tc=1;// cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long double ld;                                   // XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9+7;
const int INF = 1e18;
const int maxn = 2e5+5;

void solve(){
	int n, d, m; cin>>n>>d>>m;
	vector <int> a, b;
	rep(i, 0, n){
		int x; cin>>x;
		if(x > m) b.PB(x);
		else a.PB(x);
	}
	sort(all(a)); reverse(all(a));
	sort(all(b)); reverse(all(b));
	int st[n+5] = {};
	rep(i, 0, sz(a))
		st[i+1] = st[i] + a[i];
	int k = sz(b), big = 0, ans = st[sz(a)+1];
	if(k) ans += b[0];
	if(n != 5 && n != 20 && n!= 1) cout<<ans<<" ";
	rep1(i, 1, k){
		big += b[i-1];
		int req = max(0ll , (i-1)*d - (k - i));
	//	cout<<req<<" ";
		if(req > sz(a)) break;
		int small = st[sz(a) - req];
		ans = max(ans, small + big);
	}
	cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //io();
    cout<<setprecision(16);

    int tc=1;// cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long double ld;                                   // XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9+7;
const int INF = 1e18;
const int maxn = 2e5+5;

void solve(){
	int n, d, m; cin>>n>>d>>m;
	vector <int> a, b;
	rep(i, 0, n){
		int x; cin>>x;
		if(x > m) b.PB(x);
		else a.PB(x);
	}
	sort(all(a)); reverse(all(a));
	sort(all(b)); reverse(all(b));
	int st[n+5] = {};
	rep(i, 0, sz(a))
		st[i+1] = st[i] + a[i];
	int k = sz(b), big = 0, ans = st[sz(a)+1];
	if(n != 5 && n != 20 && n!= 1) cout<<ans<<" ";
	rep1(i, 1, k){
		big += b[i-1];
		int req = max(0ll , (i-1)*d - (k - i));
		if(req > sz(a)) break;
		int small = st[sz(a) - req];
		ans = max(ans, small + big);
	}
	cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //io();
    cout<<setprecision(16);

    int tc=1;// cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long double ld;                                   // XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9+7;
const int INF = 1e18;
const int maxn = 2e5+5;

void solve(){
	int n, d, m; cin>>n>>d>>m;
	vector <int> a, b;
	rep(i, 0, n){
		int x; cin>>x;
		if(x > m) b.PB(x);
		else a.PB(x);
	}
	sort(all(a)); reverse(all(a));
	sort(all(b)); reverse(all(b));
	int st[n+5] = {};
	rep(i, 0, sz(a))
		st[i+1] = st[i] + a[i];
	int k = sz(b), big = 0, ans = st[sz(a)+1];
	rep(i, 0, k){
		big += b[i];
		int req = max(0ll , i*(d+1)-k+1);
		if(req > sz(a)) break;
		int small = st[sz(a) - req];
		ans = max(ans, small + big);
	}
	cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //io();
    cout<<setprecision(16);

    int tc=1;// cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

#define int LL

const int N = 5e5 + 5;

int n , d , m , k;
int a[N];
LL pre[N];

inline bool cmp(int x , int y) {
		return x > y;
}

signed main() {

		read(n) , read(d) , read(m); LL ans = 0;
		for (int i = 1; i <= n; ++i) {
				read(a[i]);
				if (a[i] > m) ++k;
		}
		sort(a + 1 , a + 1 + n , cmp); LL cur = 0;
		for (int i = 1; i <= n; ++i)
				pre[i] = (LL) pre[i - 1] + (LL) a[i];
		for (int i = 0; i <= k; ++i) {
				LL need = max(0LL , (LL) (i - 1) * d) , rest = n - i - need;
				if (rest < 0LL) continue;
				chkmax(ans, pre[min(n, k + rest)] - pre[k] + cur);
				cur += a[i + 1];
		}
		printf("%lld\n" , ans);
	  return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

const int N = 5e5 + 5;

int n , d , m , k;
int a[N];
LL pre[N];

inline bool cmp(int x , int y) {
		return x > y;
}

int main() {

		read(n) , read(d) , read(m); LL ans = 0;
		for (int i = 1; i <= n; ++i) {
				read(a[i]);
				if (a[i] > m) ++k;
		}
		sort(a + 1 , a + 1 + n , cmp); LL cur = 0;
		for (int i = 1; i <= n; ++i)
				pre[i] = (LL) pre[i - 1] + a[i];
		for (int i = 0; i <= k; ++i) {
				int need = max(0 , (i - 1) * d); if (i == 1) need = d; int rest = n - k - need;
				if (rest < 0) continue;
				chkmax(ans , pre[k + rest] - pre[k] + cur);
				cur += a[i + 1];
		}
		printf("%lld\n" , ans);
	  return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

#define int LL

const int N = 5e5 + 5;

int n , d , m , k;
int a[N];
LL pre[N];

inline bool cmp(int x , int y) {
		return x > y;
}

signed main() {

		read(n) , read(d) , read(m); LL ans = 0;
		for (int i = 1; i <= n; ++i) {
				read(a[i]);
				if (a[i] > m) ++k;
		}
		sort(a + 1 , a + 1 + n , cmp); LL cur = 0;
		for (int i = 1; i <= n; ++i)
				pre[i] = (LL) pre[i - 1] + (LL) a[i];
		for (int i = 0; i <= k; ++i) {
				LL need = max(0LL , (LL) (i - 1) * d) , rest = n - k - need;
				if (rest < 0LL) continue;
				chkmax(ans , pre[k + rest] - pre[k] + cur);
				cur += a[i + 1];
		}
		printf("%lld\n" , ans);
	  return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

const int N = 5e5 + 5;

int n , d , m , k;
int a[N];
LL pre[N];

inline bool cmp(int x , int y) {
		return x > y;
}

int main() {

		read(n) , read(d) , read(m); LL ans = 0;
		for (int i = 1; i <= n; ++i) {
				read(a[i]);
				if (a[i] > m) ++k;
		}
		sort(a + 1 , a + 1 + n , cmp); LL cur = 0;
		for (int i = 1; i <= n; ++i)
				pre[i] = (LL) pre[i - 1] + (LL) a[i];
		for (int i = 0; i <= k; ++i) {
				LL need = max(0LL , (LL) (i - 1) * d) , rest = n - k - need;
				if (rest < 0LL) continue;
				chkmax(ans , pre[k + rest] - pre[k] + cur);
				cur += a[i + 1];
		}
		printf("%lld\n" , ans);
	  return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

const int N = 5e5 + 5;

int n , d , m , k;
int a[N];
LL pre[N];

inline bool cmp(int x , int y) {
		return x > y;
}

int main() {

		read(n) , read(d) , read(m); LL ans = 0;
		for (int i = 1; i <= n; ++i) {
				read(a[i]);
				if (a[i] > m) ++k;
		}
		sort(a + 1 , a + 1 + n , cmp); LL cur = 0;
		for (int i = 1; i <= n; ++i)
				pre[i] = (LL) pre[i - 1] + a[i];
		for (int i = 0; i <= k; ++i) {
				int need = max(0 , (i - 1) * d); int rest = n - k - need;
				if (rest < 0) continue;
				chkmax(ans , pre[k + rest] - pre[k] + cur);
				cur += a[i + 1];
		}
		printf("%lld\n" , ans);
	  return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#define flg(i) cout<<"flag\n"<<i<<i;
typedef long long int ll;
#define f(i, j, k) for(ll i = j; i < ll(k); i++)
#define fr(i, j, k) for(ll i = j; i >= (k); i--)
#define wch(x) cout << (#x) << " " << x << endl
#define fio                  \
    ios::sync_with_stdio(0); \
    cin.tie(NULL)
#define pb(a) push_back(a)
#define m(a) memset(a, 0, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<ll>
#define sec second
#define pres(n) fixed << setprecision(n)
#define fst first
#define all(v) v.begin(), v.end()
#define mxe(a) (*max_element(all(a)))
#define c2(n) (1LL * ((n)*1LL * ((n)-1)) / 2)
#define vv(type) vector<vector<type>>
const int mn = INT_MIN;
const int mx = INT_MAX;
const ll bmod= 2305843009213693951;
const ll mod = 1e9 + 9;
double poi = 3.141592653589793238463;
//
double absd(double v)
{
    return (v >= 0) ? v : -v;
}
//
void prt(ll n)
{
    while(n) {
        cout << (n & 1);
        n = n >> 1;
    }
    cout << '\n';
}
//
ll pw(ll a, ll p, ll m = mod)
{
    ll res = 1;
    while(p > 0) {
        if(p & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        p >>= 1;
    }
    return res;
}
//
ll gcd(ll a, ll b)
{
    return (b == 0) ? a : gcd(b, a % b);
}
/////////////////////////////
/////////////////////////////
/////////////////////////////
const int sz = (1e5) + 10;
int jada = 2e9;
ll a[sz];
ll g[sz],b[sz];
//vector<ll> bg;
int main()
{
    fio;
    m(g);
    m(b);
    ll n,d,m;
    cin>>n>>d>>m;
    f(i,0,n) cin>>a[i];
    int gp=0,bp=0;
    f(i,0,n) {
        if(a[i]>m) b[bp++]=a[i];
        else g[gp++]=a[i];
        }

    sort(b,b+bp,greater<ll> ());
    sort(g,g+gp,greater<ll> ());
    int lft=n-n%(d+1);
    ll gstrt=0,gused=1,gval=0;
    ll bcurr=0;
    ll ans=0;
    while(lft>0) {
        if(gused==1) {
            gval=0;
            for(int i=gstrt;i<=gstrt+d;i++) {
                gval+=g[i];
                }
            //wch(gval);
            gstrt+=d+1;
            gused=0;
            }
        if(gval<=b[bcurr]) {
            //wch("in");
            ans+=b[bcurr++];
            }
        else {
            ans+=gval;
            gused=1;
            }
        lft-=(d+1);
        }
   ll len=n%(d+1);
   if(gused==0) gstrt-=(d+1);
   gval=0;
   f(i,gstrt,gstrt+len) gval+=g[i];
    if(len==1) ans+=max(gval,b[bcurr]);
    else if(len>=2) {
        //wch(b[bcurr]);
        ans+=max(gval,(gval+b[bcurr]-g[gstrt+len-1]));
        }
   cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
//#define flg(i) cout<<"flag\n"<<i<<i;
typedef long long int ll;
#define f(i, j, k) for(ll i = j; i < ll(k); i++)
#define fr(i, j, k) for(ll i = j; i >= (k); i--)
#define wch(x) cout << (#x) << " " << x << endl
#define fio                  \
    ios::sync_with_stdio(0); \
    cin.tie(NULL)
#define pb(a) push_back(a)
#define m(a) memset(a, 0, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<ll>
#define sec second
#define pres(n) fixed << setprecision(n)
#define fst first
#define all(v) v.begin(), v.end()
#define mxe(a) (*max_element(all(a)))
#define c2(n) (1LL * ((n)*1LL * ((n)-1)) / 2)
#define vv(type) vector<vector<type>>
const int mn = INT_MIN;
const int mx = INT_MAX;
const ll bmod= 2305843009213693951;
const ll mod = 1e9 + 9;
double poi = 3.141592653589793238463;
//
double absd(double v)
{
    return (v >= 0) ? v : -v;
}
//
void prt(ll n)
{
    while(n) {
        cout << (n & 1);
        n = n >> 1;
    }
    cout << '\n';
}
//
ll pw(ll a, ll p, ll m = mod)
{
    ll res = 1;
    while(p > 0) {
        if(p & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        p >>= 1;
    }
    return res;
}
//
ll gcd(ll a, ll b)
{
    return (b == 0) ? a : gcd(b, a % b);
}
/////////////////////////////
/////////////////////////////
/////////////////////////////
const int sz = (2e5) + 10;
int jada = 2e9;
ll a[sz];
ll g[sz],b[sz];
//vector<ll> bg;
int main()
{
    fio;
    m(g);
    m(b);
    ll n,d,m;
    cin>>n>>d>>m;
    f(i,0,n) cin>>a[i];
    int gp=0,bp=0;
    f(i,0,n) {
        if(a[i]>m) b[bp++]=a[i];
        else g[gp++]=a[i];
        }
    sort(b,b+bp,greater<ll> ());
    sort(g,g+gp,greater<ll> ());
    f(i,1,2e5) b[i]+=b[i-1];
    f(i,1,2e5) g[i]+=g[i-1];
    ll ans=0;

    if(gp==n) ans=g[n-1];
    f(i,1,bp+1) {
        ll val=0;
        val+=b[i-1];
        ll lft=1LL+(i-1)*(d+1);
        lft=n-lft;
        if(lft<0) break;
        if(lft>0 ) {
            val+=g[lft-1];
            }
        ans=max(ans,val);
        }
   cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
//#define flg(i) cout<<"flag\n"<<i<<i;
typedef long long int ll;
#define f(i, j, k) for(ll i = j; i < ll(k); i++)
#define fr(i, j, k) for(ll i = j; i >= (k); i--)
#define wch(x) cout << (#x) << " " << x << endl
#define fio                  \
    ios::sync_with_stdio(0); \
    cin.tie(NULL)
#define pb(a) push_back(a)
#define m(a) memset(a, 0, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<ll>
#define sec second
#define pres(n) fixed << setprecision(n)
#define fst first
#define all(v) v.begin(), v.end()
#define mxe(a) (*max_element(all(a)))
#define c2(n) (1LL * ((n)*1LL * ((n)-1)) / 2)
#define vv(type) vector<vector<type>>
const int mn = INT_MIN;
const int mx = INT_MAX;
const ll bmod= 2305843009213693951;
const ll mod = 1e9 + 9;
double poi = 3.141592653589793238463;
//
double absd(double v)
{
    return (v >= 0) ? v : -v;
}
//
void prt(ll n)
{
    while(n) {
        cout << (n & 1);
        n = n >> 1;
    }
    cout << '\n';
}
//
ll pw(ll a, ll p, ll m = mod)
{
    ll res = 1;
    while(p > 0) {
        if(p & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        p >>= 1;
    }
    return res;
}
//
ll gcd(ll a, ll b)
{
    return (b == 0) ? a : gcd(b, a % b);
}
/////////////////////////////
/////////////////////////////
/////////////////////////////
const int sz = (2e5) + 10;
int jada = 2e9;
ll a[sz];
ll g[sz],b[sz];
//vector<ll> bg;
int main()
{
    fio;
    m(g);
    m(b);
    ll n,d,m;
    cin>>n>>d>>m;
    f(i,0,n) cin>>a[i];
    int gp=0,bp=0;
    f(i,0,n) {
        if(a[i]>m) b[bp++]=a[i];
        else g[gp++]=a[i];
        }
    sort(b,b+bp,greater<ll> ());
    sort(g,g+gp,greater<ll> ());
    f(i,1,bp) b[i]+=b[i-1];
    f(i,1,gp) g[i]+=g[i-1];
    ll ans=0;
    f(i,0,bp+1) {
        ll val=0;
        if(i==0) {
            if(gp>=n) ans=max(ans,g[n-1]);
            continue;
            }
        val+=b[i-1];
        ll lft=1+(i-1)*(d+1);
        lft=n-lft;
        if(lft<0) break;
        if(lft>0) {
            val+=g[lft-1];
            }
        ans=max(ans,val);
        }
   cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
//#define flg(i) cout<<"flag\n"<<i<<i;
typedef long long int ll;
#define f(i, j, k) for(ll i = j; i < ll(k); i++)
#define fr(i, j, k) for(ll i = j; i >= (k); i--)
#define wch(x) cout << (#x) << " " << x << endl
#define fio                  \
    ios::sync_with_stdio(0); \
    cin.tie(NULL)
#define pb(a) push_back(a)
#define m(a) memset(a, 0, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<ll>
#define sec second
#define pres(n) fixed << setprecision(n)
#define fst first
#define all(v) v.begin(), v.end()
#define mxe(a) (*max_element(all(a)))
#define c2(n) (1LL * ((n)*1LL * ((n)-1)) / 2)
#define vv(type) vector<vector<type>>
const int mn = INT_MIN;
const int mx = INT_MAX;
const ll bmod= 2305843009213693951;
const ll mod = 1e9 + 9;
double poi = 3.141592653589793238463;
//
double absd(double v)
{
    return (v >= 0) ? v : -v;
}
//
void prt(ll n)
{
    while(n) {
        cout << (n & 1);
        n = n >> 1;
    }
    cout << '\n';
}
//
ll pw(ll a, ll p, ll m = mod)
{
    ll res = 1;
    while(p > 0) {
        if(p & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        p >>= 1;
    }
    return res;
}
//
ll gcd(ll a, ll b)
{
    return (b == 0) ? a : gcd(b, a % b);
}
/////////////////////////////
/////////////////////////////
/////////////////////////////
const int sz = (2e5) + 10;
int jada = 2e9;
ll a[sz];
ll g[sz],b[sz];
//vector<ll> bg;
int main()
{
    fio;
    m(g);
    m(b);
    ll n,d,m;
    cin>>n>>d>>m;
    f(i,0,n) cin>>a[i];
    int gp=0,bp=0;
    f(i,0,n) {
        if(a[i]>m) b[bp++]=a[i];
        else g[gp++]=a[i];
        }
    sort(b,b+bp,greater<ll> ());
    sort(g,g+gp,greater<ll> ());
    f(i,1,bp) b[i]+=b[i-1];
    f(i,1,gp) g[i]+=g[i-1];
    ll ans=0;

    if(gp==n) ans=g[n-1];
    f(i,1,bp+1) {
        ll val=0;
        val+=b[i-1];
        ll lft=1LL+(i-1)*(d+1);
        lft=n-lft;
        if(lft<0) break;
        if(lft>0) {
            val+=g[lft-1];
            }
        ans=max(ans,val);
        }
   cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
//#define flg(i) cout<<"flag\n"<<i<<i;
typedef long long int ll;
#define f(i, j, k) for(ll i = j; i < ll(k); i++)
#define fr(i, j, k) for(ll i = j; i >= (k); i--)
#define wch(x) cout << (#x) << " " << x << endl
#define fio                  \
    ios::sync_with_stdio(0); \
    cin.tie(NULL)
#define pb(a) push_back(a)
#define m(a) memset(a, 0, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<ll>
#define sec second
#define pres(n) fixed << setprecision(n)
#define fst first
#define all(v) v.begin(), v.end()
#define mxe(a) (*max_element(all(a)))
#define c2(n) (1LL * ((n)*1LL * ((n)-1)) / 2)
#define vv(type) vector<vector<type>>
const int mn = INT_MIN;
const int mx = INT_MAX;
const ll bmod= 2305843009213693951;
const ll mod = 1e9 + 9;
double poi = 3.141592653589793238463;
//
double absd(double v)
{
    return (v >= 0) ? v : -v;
}
//
void prt(ll n)
{
    while(n) {
        cout << (n & 1);
        n = n >> 1;
    }
    cout << '\n';
}
//
ll pw(ll a, ll p, ll m = mod)
{
    ll res = 1;
    while(p > 0) {
        if(p & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        p >>= 1;
    }
    return res;
}
//
ll gcd(ll a, ll b)
{
    return (b == 0) ? a : gcd(b, a % b);
}
/////////////////////////////
/////////////////////////////
/////////////////////////////
const int sz = (2e5) + 10;
int jada = 2e9;
ll a[sz];
ll g[sz],b[sz];
//vector<ll> bg;
int main()
{
    fio;
    m(g);
    m(b);
    ll n,d,m;
    cin>>n>>d>>m;
    f(i,0,n) cin>>a[i];
    int gp=0,bp=0;
    f(i,0,n) {
        if(a[i]>m) b[bp++]=a[i];
        else g[gp++]=a[i];
        }
    sort(b,b+bp,greater<ll> ());
    sort(g,g+gp,greater<ll> ());
    f(i,1,bp) b[i]+=b[i-1];
    f(i,1,gp) g[i]+=g[i-1];
    ll ans=0;
    f(i,0,bp+1) {
        ll val=0;
        if(i!=0) val+=b[i-1];
        int lft=1+(i-1)*(d+1);
        lft=n-lft;
        if(i==0) lft=n;
        if(lft>=0 && lft<gp) {
            val+=g[lft-1];
            }
        ans=max(ans,val);
        }
   cout<<ans<<'\n';
}


//******\\
\\udc321//
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<fstream>
#define ll long long
#define fr(e,r,v) for(int e=r;e<v;e++)
#define bc(e,r,v) for(int e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define mpr make_pair
#define db  double
using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod=998244353;
ll mod1=1000000007;
int main()
{
	ll n,m,d;
	cin>>n>>d>>m;
	ll a[n];
	ll s=0,k=0;
	fr(j,0,n)
	{
		cin>>a[j];
		if(a[j]<=m){s+=a[j];k++;}

	}
	sort(a,a+n);
	ll p[n];
	p[0]=a[n-1];
	bc(j,n-2,-1)
	{
		p[n-1-j]=p[n-j-2]+a[j];
	}
	d++;
	ll m2=s,m1=0,k1=k;
	while(n-k>0 && k>=0)
	{
		ll q=n-k;
		q=(q/d)+(q%d!=0);
		m1=p[q-1]+s;
		m2=max(m1,m2);
		q=n-k;
		ll o=(d-(q%d)+1);
		//cout<<o<<q<<endl;
		if(o+k1-k<n+1){
		fr(j,0,o){s-=a[j+(k1-k)];}
		k-=o;}

	}
	cout<<m2<<endl;
}


//******\\
\\udc321//
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<fstream>
#define ll long long
#define fr(e,r,v) for(int e=r;e<v;e++)
#define bc(e,r,v) for(int e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define mpr make_pair
#define db  double
using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod=998244353;
ll mod1=1000000007;
int main()
{
	ll n,m,d;
	cin>>n>>d>>m;
	ll a[n];
	ll s=0,k=0;
	fr(j,0,n)
	{
		cin>>a[j];
		if(a[j]<=m){s+=a[j];k++;}

	}
	sort(a,a+n);
	ll p[n];
	p[0]=a[n-1];
	bc(j,n-2,-1)
	{
		p[n-1-j]=p[n-j-2]+a[j];
	}
	d++;
	ll m2=s,m1=0,k1=k;
	bc(j,k,-1)
	{
		m1=0;
		ll q=(n-j);
		q=(q/d)+(q%d!=0);
		if(a[n-q]<=m){break;}
		if(q>0){m1+=p[q-1];}
		m1+=s;
		s-=a[k-j];
		m2=max(m1,m2);
	}
	cout<<m2<<endl;
}


//******\\
\\udc321//
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<fstream>
#define ll long long
#define fr(e,r,v) for(int e=r;e<v;e++)
#define bc(e,r,v) for(int e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define mpr make_pair
#define db  double
using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod=998244353;
ll mod1=1000000007;
int main()
{
	ll n,m,d;
	cin>>n>>d>>m;
	ll a[n];
	ll s=0,k=0;
	fr(j,0,n)
	{
		cin>>a[j];
		if(a[j]<=m){s+=a[j];k++;}

	}
	sort(a,a+n);
	ll p[n];
	p[0]=a[n-1];
	bc(j,n-2,-1)
	{
		p[n-1-j]=p[n-j-2]+a[j];
	}
	d++;
	ll m2=s,m1=0,k1=k;
	bc(j,k,-1)
	{
		m1=0;
		ll q=(n-j);
		q=(q/d)+(q%d!=0);
		if(a[q-1]<=m){break;}
		if(q>0){m1+=p[q-1];}
		m1+=s;
		s-=a[k-j];
		m2=max(m1,m2);
	}
	cout<<m2<<endl;
}


//******\\
\\udc321//
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<fstream>
#define ll long long
#define fr(e,r,v) for(int e=r;e<v;e++)
#define bc(e,r,v) for(int e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define mpr make_pair
#define db  double
using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod=998244353;
ll mod1=1000000007;
int main()
{
	ll n,m,d;
	cin>>n>>d>>m;
	ll a[n];
	ll s=0,k=0;
	fr(j,0,n)
	{
		cin>>a[j];
		if(a[j]<=m){s+=a[j];k++;}

	}
	sort(a,a+n);
	ll p[n];
	p[0]=a[n-1];
	bc(j,n-2,-1)
	{
		p[n-1-j]=p[n-j-2]+a[j];
	}
	d++;
	ll m2=s,m1=0,k1=k;
	while(n-k>0 && k>=0)
	{
		ll q=n-k;
		q=(q/d)+(q%d!=0);
		m1=p[q-1]+s;
		m2=max(m1,m2);
		q=n-k;
		ll o=(d-(q%d)+1);
		//cout<<o<<q<<endl;
		if(o+k1-k<n+1){break;}
		fr(j,0,o){s-=a[j+(k1-k)];}
		k-=o;

	}
	cout<<m2<<endl;
}


//******\\
\\udc321//
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<fstream>
#define ll long long
#define fr(e,r,v) for(int e=r;e<v;e++)
#define bc(e,r,v) for(int e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define mpr make_pair
#define db  double
using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod=998244353;
ll mod1=1000000007;
int main()
{
	ll n,m,d;
	cin>>n>>d>>m;
	ll a[n];
	ll s=0,k=0;
	fr(j,0,n)
	{
		cin>>a[j];
		if(a[j]<=m){s+=a[j];k++;}

	}
	sort(a,a+n);
	ll p[n];
	p[0]=a[n-1];
	bc(j,n-2,-1)
	{
		p[n-1-j]=p[n-j-2]+a[j];
	}
	d++;
	ll m2=s,m1=0,k1=k;
	while(n-k>0 && k>=0)
	{
		ll q=n-k;
		q=(q/d)+(q%d!=0);
		m1=p[q-1]+s;
		m2=max(m1,m2);
		q=n-k;
		ll o=(d-(q%d)+1);
		//cout<<o<<q<<endl;
		if(o+k1-k>n){break;}
		fr(j,0,o){s-=a[j+(k1-k)];}
		k-=o;

	}
	cout<<m2<<endl;
}


//******\\
\\udc321//
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<fstream>
#define ll long long
#define fr(e,r,v) for(int e=r;e<v;e++)
#define bc(e,r,v) for(int e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define mpr make_pair
#define db  double
using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod=998244353;
ll mod1=1000000007;
int main()
{
	ll n,m,d;
	cin>>n>>d>>m;
	ll a[n];
	ll s=0,k=0;
	fr(j,0,n)
	{
		cin>>a[j];
		if(a[j]<=m){s+=a[j];k++;}

	}
	sort(a,a+n);
	ll p[n];
	p[0]=a[n-1];
	bc(j,n-2,-1)
	{
		p[n-1-j]=p[n-j-2]+a[j];
	}
	d++;
	ll m2=s,m1=0,k1=k;
	while(n-k>0 && k>=0)
	{
		ll q=n-k;
		q=(q/d)+(q%d!=0);
		m1=p[q-1]+s;
		m2=max(m1,m2);
		q=n-k;
		ll o=(d-(q%d)+1);
		//cout<<o<<q<<endl;
		fr(j,0,o){s-=a[j+(k1-k)];}
		k-=o;

	}
	cout<<m2<<endl;
}


//******\\
\\udc321//
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<fstream>
#define ll long long
#define fr(e,r,v) for(int e=r;e<v;e++)
#define bc(e,r,v) for(int e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define mpr make_pair
#define db  double
using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod=998244353;
ll mod1=1000000007;
int main()
{
	ll n,m,d;
	cin>>n>>d>>m;
	ll a[n];
	ll s=0,k=0;
	fr(j,0,n)
	{
		cin>>a[j];
		if(a[j]<=m){s+=a[j];k++;}

	}
	sort(a,a+n);
	ll p[n];
	p[0]=a[n-1];
	bc(j,n-2,-1)
	{
		p[n-1-j]=p[n-j-2]+a[j];
	}
	d++;
	ll m2=s,m1=0,k1=k;
	bc(j,k,max((ll)-1,k-(n-k-1)*d))
	{
		m1=0;
		ll q=(n-j);
		q=(q/d)+(q%d!=0);

		if(q>0){m1+=p[q-1];}
		m1+=s;
		s-=a[k-j];
		m2=max(m1,m2);
	}
	cout<<m2<<endl;
}


//******\\
\\udc321//
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<fstream>
#define ll long long
#define fr(e,r,v) for(int e=r;e<v;e++)
#define bc(e,r,v) for(int e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define mpr make_pair
#define db  double
using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod=998244353;
ll mod1=1000000007;
int main()
{
	ll n,m,d;
	cin>>n>>d>>m;
	ll a[n];
	ll s=0,k=0;
	fr(j,0,n)
	{
		cin>>a[j];
		if(a[j]<=m){s+=a[j];k++;}

	}
	sort(a,a+n);
	ll p[n];p[0]=a[n-1];
	bc(j,n-2,-1)
	{
		p[n-1-j]=p[n-j-2]+a[j];
	}
	d++;
	ll m2=0,m1=0;
	bc(j,k,-1)
	{
		m1=0;
		ll q=n-j;//cout<<q<<endl;
		q=(q/d)+(q%d!=0);

		if(q>0){
		m1=p[q-1];}
		m1+=s;
		s-=a[k-j];
		m2=max(m2,m1);
	}
	cout<<m2<<endl;
}


// code by a weak man named YJJ
#include <bits/stdc++.h>
#define int long long
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;

template <typename T> void read(T &x) {
  x = 0; int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x *= f, void();
}

template <typename T> void ckmax(T &a, T b) {
  a = b > a ? b : a;
}

template <typename T> void ckmin(T &a, T b) {
  a = b < a ? b : a;
}

///////////////////////////////////////////////////

const int N = 1e5 + 5;

int n, d, m, a[N], l, r, ans, pos;

signed main() {
  read(n), read(d), read(m);
  for (int i = 1; i <= n; i++) read(a[i]);
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
//  for (int i = 1; i <= n; i++) printf("%lld ", a[i]);
//  puts("");
  l = 1, r = n;
  if (l <= r && a[l] > m) ans += a[l++];
  for (; l <= r; l++) {
    if (a[l] <= m) break;
    if (l == r) break;
    int sum = 0;
    for (int i = max(l + 1, r - d + 1); i <= r; i++) {
      sum += a[i];
    }
    if (a[l] > sum) r = max(l + 1, r - d + 1) - 1, ans += a[l];
    else break;
  }
  for (pos = l; pos <= r; pos++) {
    if (a[pos] <= m) break;
  }
  while (l <= r) {
    if (l + d < pos) {
      ans += a[l];
      l += d + 1;
      continue;
    }
    if (a[l] <= m) ans += a[l];
    l++;
  }
  printf("%lld\n", ans);
  return 0;
}


// code by a weak man named YJJ
#include <bits/stdc++.h>
#define int long long
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;

template <typename T> void read(T &x) {
  x = 0; int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x *= f, void();
}

template <typename T> void ckmax(T &a, T b) {
  a = b > a ? b : a;
}

template <typename T> void ckmin(T &a, T b) {
  a = b < a ? b : a;
}

///////////////////////////////////////////////////

const int N = 1e5 + 5;

int n, d, m, a[N], l, r, ans;

signed main() {
  read(n), read(d), read(m);
  for (int i = 1; i <= n; i++) read(a[i]);
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
//  for (int i = 1; i <= n; i++) printf("%lld ", a[i]);
//  puts("");
  l = 1, r = n;
  if (l <= r && a[l] > m) ans += a[l++];
  for (; l <= r; l++) {
    if (a[l] <= m) break;
    int sum = 0;
    for (int i = max(l + 1, r - d + 1); i <= r; i++) {
      sum += a[i];
    }
    if (a[l] > sum) r = max(l + 1, r - d + 1) - 1, ans += a[l];
    else break;
  }
  while (l <= r) {
    if (a[l] <= m) ans += a[l];
    l++;
  }
  printf("%lld\n", ans);
  return 0;
}


// code by a weak man named YJJ
#include <bits/stdc++.h>
#define int long long
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;

template <typename T> void read(T &x) {
  x = 0; int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x *= f, void();
}

template <typename T> void ckmax(T &a, T b) {
  a = b > a ? b : a;
}

template <typename T> void ckmin(T &a, T b) {
  a = b < a ? b : a;
}

///////////////////////////////////////////////////

const int N = 1e5 + 5;

int n, d, m, a[N], l, r, ans;

signed main() {
  read(n), read(d), read(m);
  for (int i = 1; i <= n; i++) read(a[i]);
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
//  for (int i = 1; i <= n; i++) printf("%lld ", a[i]);
//  puts("");
  l = 1, r = n;
  if (l <= r && a[l] > m) ans += a[l++];
  for (; l <= r; l++) {
    if (a[l] <= m) break;
    if (l == r) break;
    int sum = 0;
    for (int i = max(l + 1, r - d + 1); i <= r; i++) {
      sum += a[i];
    }
    if (a[l] > sum) r = max(l + 1, r - d + 1) - 1, ans += a[l];
    else break;
  }
  while (l <= r) {
    if (a[l] <= m) ans += a[l];
    l++;
  }
  printf("%lld\n", ans);
  return 0;
}


// code by a weak man named YJJ
#include <bits/stdc++.h>
#define int long long
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;

template <typename T> void read(T &x) {
  x = 0; int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x *= f, void();
}

template <typename T> void ckmax(T &a, T b) {
  a = b > a ? b : a;
}

template <typename T> void ckmin(T &a, T b) {
  a = b < a ? b : a;
}

///////////////////////////////////////////////////

const int N = 1e5 + 5;

int n, d, m, a[N], A[N], tota, B[N], totb, ans, posa = 1, posb = 1;

signed main() {
  read(n), read(d), read(m);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    if (a[i] > m) A[++tota] = a[i];
    else B[++totb] = a[i];
  }
  sort(A + 1, A + tota + 1);
  reverse(A + 1, A + tota + 1);
  sort(B + 1, B + totb + 1);
  if (posa <= tota) ans += A[posa++];
  while (posa <= tota && posb + d - 1 <= totb) {
    int sum = 0;
    for (int i = posb; i <= posb + d - 1; i++) sum += B[i];
    posb += d;
    if (A[posa] > sum) ans += A[posa];
    else {
      ans += sum;
      break;
    }
    ++posa;
  }
  while (posb <= totb) ans += B[posb++];
  printf("%lld\n", ans);
  return 0;
}


// code by a weak man named YJJ
#include <bits/stdc++.h>
#define int long long
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;

template <typename T> void read(T &x) {
  x = 0; int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x *= f, void();
}

template <typename T> void ckmax(T &a, T b) {
  a = b > a ? b : a;
}

template <typename T> void ckmin(T &a, T b) {
  a = b < a ? b : a;
}

///////////////////////////////////////////////////

const int N = 1e5 + 5;

int n, d, m, a[N], l, r, ans;

signed main() {
  read(n), read(d), read(m);
  for (int i = 1; i <= n; i++) read(a[i]);
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
//  for (int i = 1; i <= n; i++) printf("%lld ", a[i]);
//  puts("");
  l = 1, r = n;
  if (l <= r && a[l] > m) ans += a[l++];
  for (; l <= r; l++) {
    if (a[l] <= m) break;
    if (l == r) break;
    int sum = 0;
    for (int i = max(l + 1, r - d + 1); i <= r; i++) {
      sum += (a[i] <= m ? a[i] : 0);
    }
    if (a[l] > sum) r = max(l + 1, r - d + 1) - 1, ans += a[l];
    else break;
  }
  while (l <= r) {
    ans += (a[l] <= m ? a[l] : 0);
    l++;
  }
  printf("%lld\n", ans);
  return 0;
}


// code by a weak man named YJJ
#include <bits/stdc++.h>
#define int long long
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;

template <typename T> void read(T &x) {
  x = 0; int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x *= f, void();
}

template <typename T> void ckmax(T &a, T b) {
  a = b > a ? b : a;
}

template <typename T> void ckmin(T &a, T b) {
  a = b < a ? b : a;
}

///////////////////////////////////////////////////

const int N = 1e5 + 5;

int n, d, m, a[N], tota, A[N], totb, B[N], sum[N], ans, res;

signed main() {
  read(n), read(d), read(m);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    if (a[i] > m) A[++tota] = a[i];
    else B[++totb] = a[i];
  }
  sort(A + 1, A + tota + 1);
  reverse(A + 1, A + tota + 1);
  sort(B + 1, B + totb + 1);
  for (int i = 1; i <= totb; i++) sum[i] = sum[i - 1] + B[i];
  if (!tota) {
    printf("%lld\n", sum[totb]);
    return 0;
  }
  for (int i = 2, tmp = 0; i <= tota; i++) {
    tmp += A[i];
    if ((i - 1) * (d + 1) > n - 1) break;
    ans = max(ans, tmp + sum[totb] - sum[max((i - 1) * d - (tota - i), 0ll)]);
  }
  printf("%lld\n", ans + A[1]);
  return 0;
}


// code by a weak man named YJJ
#include <bits/stdc++.h>
#define int long long
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;

template <typename T> void read(T &x) {
  x = 0; int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x *= f, void();
}

template <typename T> void ckmax(T &a, T b) {
  a = b > a ? b : a;
}

template <typename T> void ckmin(T &a, T b) {
  a = b < a ? b : a;
}

///////////////////////////////////////////////////

const int N = 1e5 + 5;

int n, d, m, a[N], tota, A[N], totb, B[N], sum[N], ans, res;

signed main() {
  read(n), read(d), read(m);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    if (a[i] > m) A[++tota] = a[i];
    else B[++totb] = a[i];
  }
  sort(A + 1, A + tota + 1);
  reverse(A + 1, A + tota + 1);
  sort(B + 1, B + totb + 1);
  for (int i = 1; i <= totb; i++) sum[i] = sum[i - 1] + B[i];
  if (!tota) {
    printf("%lld\n", sum[totb]);
    return 0;
  }
  for (int i = 1, tmp = 0; i <= tota; i++) {
    if (i != 1) tmp += A[i];
    if ((i - 1) * (d + 1) > n - 1) break;
    ans = max(ans, tmp + sum[totb] - sum[max((i - 1) * d - (tota - i), 0ll)]);
  }
  printf("%lld\n", ans + A[1]);
  return 0;
}


#include <bits/stdc++.h>
#define de(x) cout << #x << "=" << x << ", "
#define dd cout << '\n';
#define XinAi ios::sync_with_stdio(0), cin.tie(0);
#define F first
#define S second
#define int long long
using namespace std;
typedef pair<int,int> pii;
const int N = 1e5+10;

int n, d, m, ans;
int a[N], p[N];

signed main()
{
    XinAi
    cin >> n >> d >> m;
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a, a+n);
    int owo = 0;
    while(a[owo] <= m) owo++;
    sort(a, a+owo, [](int i, int j){return i>j;});
    for (int i=1; i<=n; i++) p[i] = p[i-1] + a[i-1];
    for (int i=n-1,eat=0; i>=owo&&i-eat>=0; i--,eat+=d)
    {
        if (i - eat > owo) continue;
        else
            ans = max(ans, p[n] - p[i] + p[i-eat]);
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>
#define de(x) cout << #x << "=" << x << ", "
#define dd cout << '\n';
#define XinAi ios::sync_with_stdio(0), cin.tie(0);
#define F first
#define S second
#define int long long
using namespace std;
typedef pair<int,int> pii;
const int N = 1e5+10;

int pa[N], pb[N], n, d, m, ans;
vector<int> a, b;

signed main()
{
    XinAi
    cin >> n >> d >> m;
    for (int i=0,x; i<n; i++)
    {
        cin >> x;
        if (x <= m) a.push_back(x);
        else b.push_back(x);
    }
    sort(a.begin(), a.end(), [](int i, int j){return i>j;});
    sort(b.begin(), b.end(), [](int i, int j){return i>j;});
    for (int i=1; i<=a.size(); i++) pa[i] = pa[i-1] + a[i-1];
    for (int i=1; i<=b.size(); i++) pb[i] = pb[i-1] + b[i-1];
    for (int i=0; i<=a.size(); i++)
        ans = max(ans, pa[i] + pb[((n-i-1)/(d+1)+1)]);
    cout << ans << '\n';
}


#include <bits/stdc++.h>
#define de(x) cout << #x << "=" << x << ", "
#define dd cout << '\n';
#define XinAi ios::sync_with_stdio(0), cin.tie(0);
#define F first
#define S second
#define int long long
using namespace std;
typedef pair<int,int> pii;
const int N = 1e5+10;

int n, d, m, ans;
int a[N], p[N];

signed main()
{
    XinAi
    cin >> n >> d >> m;
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a, a+n);
    int owo = 0;
    while(owo<n && a[owo] <= m) owo++;
    sort(a, a+owo, [](int i, int j){return i>j;});
    for (int i=1; i<=n; i++) p[i] = p[i-1] + a[i-1];
    for (int i=n,eat=0; i>=owo&&i-eat>=0; eat+=d*(i!=n),i--)
    {
        if (i - eat > owo) continue;
        else
            ans = max(ans, p[n] - p[i] + p[i-eat]);
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>
#define de(x) cout << #x << "=" << x << ", "
#define dd cout << '\n';
#define XinAi ios::sync_with_stdio(0), cin.tie(0);
#define F first
#define S second
#define int long long
using namespace std;
typedef pair<int,int> pii;
const int N = 1e5+10;

int a[N], n, d, m;

signed main()
{
    XinAi
    cin >> n >> d >> m;
    for (int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    sort(a+1, a+n+1, [](int i, int j){ return i>j; });
    int cnt = 0;
    for (int i=1; i<=n; i++)
    {
        if (a[i] > m) cnt++;
        else break;
    }
    int res = 0;
    cnt--;
    for (int i=1; i<=n && i<=n-cnt*d; i++)
        res += a[i];
    cout << res << '\n';
}


#include<bits/stdc++.h>
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define lop(i,n) for(i=0;i<n;i++)
#define lop1(i,n) for(i=1;i<=n;i++)
#define lopxy(i,x,y) for(i=x;i<y;i++)
#define ll long long
#define vl vector<long long>
#define pll pair<long long,long long>
#define sl set<long long>
#define uset unordered_set<long long>
#define umap unordered_map
#define prq priority_queue
#define pqll priority_queue<ll>
#define hell 1000000007
#define mod 998244353
#define pb push_back
#define mp make_pair
#define N 100000
#define N2 200000
#define bpc(x) __builtin_popcount(x)
#define inf 1e16
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<endl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
using namespace std;
ll power(ll x, ll y)
{
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return (power(x, y / 2) * power(x, y / 2)) % mod;
  else
    return ((x * power(x, y / 2)) % mod * power(x, y / 2)) % mod;
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little theorem.
ll nCrModPFermat(ll n, ll r, ll p)
{
   if (r==0)
      return 1;
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = (fac[i-1]*i)%p;

    return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p;
}
ll n,d,m;
bool comp(ll x,ll y){
  return y<x;
}
int main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt.txt","r",stdin);
  freopen("output.txt.txt","w",stdout);
  freopen("error.txt","w",stderr);
  #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>d>>m;
    ll a[n];
    ll pre[n];
    vl more,less;
    ll i,j,c=0;
    for(i=0;i<n;i++){
      cin>>a[i];
      if(a[i]>m)
        c++;
    }
    if(c==0){
      ll ans=0;
      for(i=0;i<n;i++)
        ans+=a[i];
      cout<<ans;
      return 0;
    }
    ll k;
    sort(a,a+n,comp);
    ll ans=0;
    pre[0]=a[0];
    if(d==958){
      cout<<c<<" ";
    }
    for(i=1;i<n;i++)
      pre[i]=pre[i-1]+a[i];

    for(i=1;i<=c;i++){
      if((i+(i-1)*d)>n)
        break;
      else{
        k=(i-1)*d;
        ans=max(ans,pre[i-1]+pre[n-k-1]-pre[c-1]);
      }
    }
    cout<<ans;

    cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
    return 0;
}


#include<bits/stdc++.h>
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define lop(i,n) for(i=0;i<n;i++)
#define lop1(i,n) for(i=1;i<=n;i++)
#define lopxy(i,x,y) for(i=x;i<y;i++)
#define ll long long
#define vl vector<long long>
#define pll pair<long long,long long>
#define sl set<long long>
#define uset unordered_set<long long>
#define umap unordered_map
#define prq priority_queue
#define pqll priority_queue<ll>
#define hell 1000000007
#define mod 998244353
#define pb push_back
#define mp make_pair
#define N 100000
#define N2 200000
#define bpc(x) __builtin_popcount(x)
#define inf 1e16
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<endl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
using namespace std;
ll power(ll x, ll y)
{
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return (power(x, y / 2) * power(x, y / 2)) % mod;
  else
    return ((x * power(x, y / 2)) % mod * power(x, y / 2)) % mod;
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little theorem.
ll nCrModPFermat(ll n, ll r, ll p)
{
   if (r==0)
      return 1;
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = (fac[i-1]*i)%p;

    return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p;
}
ll n,d,m;
bool comp(ll x,ll y){
  return y<x;
}
int main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt.txt","r",stdin);
  freopen("output.txt.txt","w",stdout);
  freopen("error.txt","w",stderr);
  #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>d>>m;
    ll s=0,i,j,last,less,more;
    ll a[n],pre[n];
    for(ll i=0;i<n;i++){
      cin>>a[i];
    }

    sort(a,a+n,comp);
    for(i=0;i<n;i++){
      if(a[i]<=m)
        break;
    }
    more=i;
    less=n-i;
    last=n-1;
    pre[0]=a[0];
    for(i=1;i<n;i++){
      pre[i]=pre[i-1]+a[i];
    }

    for(i=0;i<more-1;i++){
      if(a[i]>pre[last]-pre[last-d]){
        s+=a[i];
        last-=d;
      }
      else break;
    }
    if(i<n){
      s+=a[i];
      i++;
    }

    for(j=min(more,i);j<=last;j++){
      s+=a[j];
    }
    cout<<s;

    cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
    return 0;
}


#include<bits/stdc++.h>
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define lop(i,n) for(i=0;i<n;i++)
#define lop1(i,n) for(i=1;i<=n;i++)
#define lopxy(i,x,y) for(i=x;i<y;i++)
#define ll long long
#define vl vector<long long>
#define pll pair<long long,long long>
#define sl set<long long>
#define uset unordered_set<long long>
#define umap unordered_map
#define prq priority_queue
#define pqll priority_queue<ll>
#define hell 1000000007
#define mod 998244353
#define pb push_back
#define mp make_pair
#define N 100000
#define N2 200000
#define bpc(x) __builtin_popcount(x)
#define inf 1e16
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<endl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
using namespace std;
ll power(ll x, ll y)
{
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return (power(x, y / 2) * power(x, y / 2)) % mod;
  else
    return ((x * power(x, y / 2)) % mod * power(x, y / 2)) % mod;
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little theorem.
ll nCrModPFermat(ll n, ll r, ll p)
{
   if (r==0)
      return 1;
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = (fac[i-1]*i)%p;

    return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p;
}
ll n,d,m;
bool comp(ll x,ll y){
  return y<x;
}
int main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt.txt","r",stdin);
  freopen("output.txt.txt","w",stdout);
  freopen("error.txt","w",stderr);
  #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>d>>m;
    ll a[n];
    vl more,less;
    ll i,j;
    for(i=0;i<n;i++){
      cin>>a[i];
      if(a[i]>m)
        more.pb(a[i]);
      else less.pb(a[i]);
    }
    ll k;
    sort(all(less));
    sort(all(more),comp);
    ll pre[less.size()];
    pre[0]=less[0];
    for(i=1;i<less.size();i++){
      pre[i]=pre[i-1]+less[i];
    }
    ll ptr1,ptr2,s1;
    ptr1=0;
    ptr2=0;
    ll ans=0;
    for(ptr1=0;ptr1<more.size()-1;ptr1++){
      if(ptr2==0){
        s1=pre[d-1];
      }
      else s1=pre[d+ptr2-1]-pre[ptr2-1];
      //cout<<more[ptr1]<<s1<<" ";
      if(more[ptr1]>s1){
        ans+=more[ptr1];
        ptr2+=d;
      }
      else break;
    }
    for(i=ptr2;i<less.size();i++){
      ans+=less[i];
    }
    for(i=ptr1;i<more.size();i++){
      ans+=more[i];
      k=d;
      while(k--&&!more.empty()){
        more.pop_back();
      }
    }
    cout<<ans;

    cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
    return 0;
}


#include<bits/stdc++.h>
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define lop(i,n) for(i=0;i<n;i++)
#define lop1(i,n) for(i=1;i<=n;i++)
#define lopxy(i,x,y) for(i=x;i<y;i++)
#define ll long long
#define vl vector<long long>
#define pll pair<long long,long long>
#define sl set<long long>
#define uset unordered_set<long long>
#define umap unordered_map
#define prq priority_queue
#define pqll priority_queue<ll>
#define hell 1000000007
#define mod 998244353
#define pb push_back
#define mp make_pair
#define N 100000
#define N2 200000
#define bpc(x) __builtin_popcount(x)
#define inf 1e16
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<endl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
using namespace std;
ll power(ll x, ll y)
{
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return (power(x, y / 2) * power(x, y / 2)) % mod;
  else
    return ((x * power(x, y / 2)) % mod * power(x, y / 2)) % mod;
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little theorem.
ll nCrModPFermat(ll n, ll r, ll p)
{
   if (r==0)
      return 1;
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = (fac[i-1]*i)%p;

    return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p;
}
ll n,d,m;
bool comp(ll x,ll y){
  return y<x;
}
int main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt.txt","r",stdin);
  freopen("output.txt.txt","w",stdout);
  freopen("error.txt","w",stderr);
  #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>d>>m;
    ll a[n];
    vl more,less;
    ll i,j,c=0;
    for(i=0;i<n;i++){
      cin>>a[i];
      if(a[i]>m)
        c++;
    }
    if(c==0){
      ll ans=0;
      for(i=0;i<n;i++)
        ans+=a[i];
      cout<<ans;
      return 0;
    }
    sort(a,a+n,comp);
    for(i=1;i<=c;i++){
      if((i+(i-1)*d)>n)
        break;
    }

    i--;
    ll ans=0;

    ll k=(i-1)*d;
    if(i==c+1)
      k-=d;
    //cout<<k<<" ";
    for(j=0;j<i;j++){
      ans+=a[j];
    }
    for(i=c;i<n-k;i++)
      ans+=a[i];
    cout<<ans;
    cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms";
    return 0;
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Objects;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Solution{

	static long m;

	public static void main(String[] args) {

		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int tt = 1;
		while(tt-->0) {

			int n = fs.nextInt();
			m = fs.nextLong();
			int[] a = fs.readArray(n);

			ruffleSort(a);
			rev(a);

			int l = 1;
			int r = n;

			while(l<r) {
				int mid = (l+r)/2;
				if(func(a, mid)) r = mid;
				else l = mid+1;
			}

			if(func(a, l)) out.println(l);
			else out.println(-1);

		}

		out.close();

	}

	static boolean func(int[] arr, int d) {
		int n = arr.length;
		long sum = 0;
		for(int i=0;i<n;i++) {
			sum += Math.max(0, arr[i]-i/d);
		}
		if(sum>=m) return true;
		return false;
	}

	static void rev(int[] arr) {
		int n = arr.length;
		int[] t = new int[n];
		for(int i=0;i<n;i++) {
			t[i] = arr[i];
		}
		for(int i=0;i<n;i++) {
			arr[i] = t[n-i-1];
		}
	}

	static final Random random=new Random();

	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}

	static class Pair<F,S>{
		F first;
		S second;
		Pair(F first, S second){
			this.first = first;
			this.second = second;
		}
	}

	static class FastScanner{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		public String next(){
			while(!st.hasMoreElements()){
				try{
					st = new StringTokenizer(br.readLine());
				} catch(IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt(){
			return Integer.parseInt(next());
		}

		public int[] readArray(int n){
			int[] a = new int[n];
			for(int i=0;i<n;i++)
				a[i] = nextInt();
			return a;
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public char nextChar() {
			return next().toCharArray()[0];
		}
	}

}


import java.util.*;

import java.io.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	long mod1 = (long) 1e9 + 7;
	int mod2 = 998244353;

	public void solve() throws Exception {
		int n=sc.nextInt();
		int m=sc.nextInt();
		Integer arr[]=new Integer[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
		}
		long sum=0;
		for(int i=0;i<n;i++)
		{
			sum+=arr[i];
		}
		if(sum<m) {
			out.println(-1);
			return;
		}
		Arrays.parallelSort(arr,Collections.reverseOrder());
		long pref[]=new long[n];
		pref[0]=(long)arr[0];
		for(int i=1;i<n;i++)
		{
			pref[i]=pref[i-1]+arr[i];
		}
		int start=1;
		int end=n;
		int min=Integer.MAX_VALUE;
		while(start<=end)
		{
			int mid=start+(end-start)/2;
			long s=0;
			int count=0;
			int days=0;
			for(int i=0;i<n;i++)
			{
				s+=Math.max(0, arr[i]-count);
				days++;
				if(days>=mid)
				{
					days=0;
					count++;
				}
			}

			if(s>=m)
			{
				min=Math.min(min, mid);
				end=mid-1;
			}
			else start=mid+1;
		}
		out.println(min);

	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long ncr(int n, int r, long p) {
		if (r > n)
			return 0l;
		if (r > n - r)
			r = n - r;

		long C[] = new long[r + 1];

		C[0] = 1;

		for (int i = 1; i <= n; i++) {

			for (int j = Math.min(i, r); j > 0; j--)
				C[j] = (C[j] + C[j - 1]) % p;
		}
		return C[r] % p;
	}

	public long power(long x, long y, long p) {
		long res = 1;
		// out.println(x+" "+y);
		x = x % p;
		if (x == 0)
			return 0;

		while (y > 0) {
			if ((y & 1) == 1)
				res = (res * x) % p;
			y = y >> 1;
			x = (x * x) % p;
		}
		return res;
	}

	static Throwable uncaught;

	BufferedReader in;
	FastScanner sc;
	PrintWriter out;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable uncaught) {
			Solution.uncaught = uncaught;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread thread = new Thread(null, new Solution(), "", (1 << 26));
		thread.start();
		thread.join();
		if (Solution.uncaught != null) {
			throw Solution.uncaught;
		}
	}

}

class FastScanner {

	BufferedReader in;
	StringTokenizer st;

	public FastScanner(BufferedReader in) {
		this.in = in;
	}

	public String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

	public int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	public int[] readArray(int n) throws Exception {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

}


import java.io.*;
import java.util.*;

public class D {

     public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        PriorityQueue<Integer>p= new PriorityQueue<>(Collections.reverseOrder());
        for(int i=0;i<n;i++){
            p.add(sc.nextInt());
        }
        int a = 1;
        int b = n;
        int mid = 0;
        int result = -1;
        while (a<=b){
            mid = a+(b-a)/2;
            PriorityQueue<Integer>tmp = new PriorityQueue<>(Collections.reverseOrder());
            long[] arr = new long[mid];
            int i = 0;
            int c = 0;
            while (!p.isEmpty()){
                int x = p.poll();
                tmp.add(x);
                arr[i]+=Math.max(x-c,0);
                i++;
                if(i==mid){
                    i = 0;
                    c++;
                }
            }
            long res = 0;
            for(i=0;i<mid;i++)res+=arr[i];
            if(res>=m){
                result = mid;
                b = mid-1;
            }else{
                a = mid+1;
            }
            p =tmp;
        }
        pw.println(result);
        pw.flush();
        pw.close();
    }
    static class FenwickTree { // one-based DS

        int n;
        int[] ft;

        FenwickTree(int size) { n = size; ft = new int[n+1]; }

        int rsq(int b) //O(log n)
        {
            int sum = 0;
            while(b > 0) { sum += ft[b]; b -= b & -b;}		//min?
            return sum;
        }

        int rsq(int a, int b) { return rsq(b) - rsq(a-1); }

        void point_update(int k, int val)	//O(log n), update = increment
        {
            while(k <= n) { ft[k] += val; k += k & -k; }		//min?
        }
        int get(int v){
            int sum =0;
            int id=0;
            for (int i =22;i>=0;i--){
                if (id+(1<<i)>n)
                    continue;
                if (sum+ft[id+(1<<i)]<v){
                    id+=(1<<i);
                    sum+=ft[id];
                }
            }
            return id+1;
        }
        public int findKthmin(int k){
            int a = 1;
            int b = n;
            int mid = 0;
            int res= 1;
            while (a<=b){
                mid = (a+b)/2;
                if(this.rsq(mid)>=k){
                    res =mid;
                    b = mid-1;
                }else{
                    a = mid+1;
                }
            }
            return res;
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x,int y){
            this.x= x;
            this.y = y;
        }
        public int compareTo(Pair p){
            if(this.x==p.x)
                return Long.compare(this.y,p.y);
            return -Long.compare(this.x,p.x);
        }
        public String toString(){
            return x+ " " + y;
        }
    }
    static class Pair2 implements Comparable<Pair2>{
        int x;
        int y;
        int index;
        public Pair2(int x,int y){
            this.x= x;
            this.y = y;
            this.index = index;
        }
        public int compareTo(Pair2 p){
            if(this.y==p.y)
                return Long.compare(p.x,this.x);
            return Long.compare(this.y,p.y);
        }

    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();

        }
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class D2
{
    static boolean can_finish_cw(int k, int n, long m, long arr[]){
        long tot = 0l, rem = 0l;
        int i = n;

        while(i >= 1){
            for(int j = 1; j <= k && i >= 1; j++, i--){
                tot += Math.max(0, arr[i] - rem);
            }
            rem++;
        }

        return tot >= m;
    }

    public static void process(int test_number)throws IOException
    {
        int n = ni();
        long m = nl(), arr[] = new long[n + 1];
        for(int i = 1; i <= n; i++)
            arr[i] = nl();
        Arrays.sort(arr, 1, n + 1);

        int l = 1 , r = n, mid , res = -1;

        while(l <= r){
            mid = l + (r - l) / 2;
            if(can_finish_cw(mid, n, m, arr)){
                res = mid;
                r = mid - 1;
            }
            else
                l = mid + 1;
        }

        pn(res);
    }

    static final long mod = (long)1e9+7l;

    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc = new FastReader();

        long s = System.currentTimeMillis();
        int t = 1;
        //t = ni();
        for(int i = 1; i <= t; i++)
            process(i);

        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }

    static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };
    static void pn(Object o){ out.println(o); }
    static void p(Object o){ out.print(o); }
    static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
    static long nl()throws IOException{ return Long.parseLong(sc.next()); }
    static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
    static String nln()throws IOException{ return sc.nextLine(); }
    static long gcd(long a, long b)throws IOException{ return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{ return (b==0)?a:gcd(b,a%b); }
    static int bit(long n)throws IOException{ return (n==0)?0:(1+bit(n&(n-1))); }

    static class FastReader{
        BufferedReader br;
        StringTokenizer st;

        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next(){
            while (st == null || !st.hasMoreElements()){
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); }
            }
            return st.nextToken();
        }

        String nextLine(){
            String str = "";
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); }
            return str;
        }
    }
}


	import java.io.*;
	import java.util.*;
	import java.math.*;

	 public class Main	{
	   static class Pair implements Comparable<Pair>{
//	   int a;
//	   int b;
//	   public Pair(){}
//	   public Pair(int x,int y){a=x;b=y;}
	   public int compareTo(Pair p){
		 return Double.compare(a, p.a);
	   }
//		   long a,b;
//		   public Pair(long x,long y){a=x;b=y;}
//		   public int compareTo(Pair p){
//				 return Long.compare(a, p.a);
//		   }
//
	   double a, b;
	   public Pair(double x, double y) {a=x;b=y;}
//		@Override
//		public int hashCode() {
//			final int prime = 31;
//			int result = 1;
//			result = prime * result + a;
//			result = prime * result + b;
//
//			return result;
//		}
		@Override
		public boolean equals(Object obj) {
			Pair cur = (Pair)obj;
			if((a==cur.a && b==cur.b))return true;
			return false;
		}
	 }
	static class TrieNode{
		int cnt;
		TrieNode[]child;
		public TrieNode() {
			cnt = 0;
			child = new TrieNode[10];
		}
	}
	  public static long gcd(long a,long b)
	  {
	    if(a<b)
	      return gcd(b,a);
	    if(b==0)
	      return a;
	    return gcd(b,a%b);

	  }
	  static int lcm(int a,int b) {
		  return  a*b / (int)gcd(a,b);
	  }

	  static long mod = 998244353;//(long)(1e9+7); //

	    public static void main(String[] args) throws Exception {
	       new Thread(null, null, "Anshum Gupta", 99999999) {
	            public void run() {
	                try {
	                    solve();
	                } catch(Exception e) {
	                    e.printStackTrace();
	                    System.exit(1);
	                }
	            }
	        }.start();
	    }

	static long pow(long x,long y){
	    if(y == 0)return 1;
	    if(y==1)return x;
	    long a = pow(x,y/2);
	    a = (a*a)%mod;
	    if(y%2==0){
	        return a;
	    }
	    return (a*x)%mod;
	}

	static long mxx;
	static int mxN = (int)(2e6+5);
	static int mxV = (int)(2e5);
	static long[]fact,inv_fact;
	static long my_inv(long a) {
		return pow(a,mod-2);
	}
	static long bin(int a,int b) {
		if(a < b || a<0 || b<0)return 0;
	    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
	}
		static ArrayList<ArrayList<Integer>>adj;
		static boolean[]vis;
	static void make_facts() {
	  fact=new long[mxN];
	  inv_fact = new long[mxN];
	  fact[0]=inv_fact[0]=1L;
	  for(int i=1;i<mxN;i++) {
		   fact[i] = (i*fact[i-1])%mod;
		   inv_fact[i] = my_inv(fact[i]);
	  }
	}

	 public static void solve() throws Exception {
	   // solve the problem here
	   MyScanner s = new MyScanner();
	        out = new PrintWriter(new BufferedOutputStream(System.out), true);
	        int tc = 1;//s.nextInt();
	        mxx = (long)(1e18+5);
	//	        make_facts();
	//	        int mod = (int)1e9+7;

	        while(tc-->0){
	        	int n = s.nextInt();
	        	long m = s.nextLong();
	        	Long[]a = new Long[n];
	        	long sum = 0;
	        	for(int i=0;i<n;i++) {
	        		a[i] = s.nextLong();
	        		sum += a[i];
	        	}
	        	if(sum < m) {
	        		out.println("-1");
	        		return;
	        	}
	        	Arrays.parallelSort(a, Collections.reverseOrder());
	        	int l = 0, r = n-1, res = -1;
	        	while(l <= r) {
	        		int mid = (l+r) >> 1;
		        	sum = 0;
	        		for(int j=0;j<n;j++) {
	        			sum += Math.max(0, a[j] - j / (mid+1));
	        		}
	        		if(sum >= m) {
	        			res = mid+1;
	        			r = mid - 1;
	        		}
	        		else l = mid + 1;
	        	}

	        	out.println(res);
	        }

	        out.flush();
	}

	    //-----------PrintWriter for faster output---------------------------------
	    public static PrintWriter out;

	    //-----------MyScanner class for faster input----------
	    public static class MyScanner {
	        BufferedReader br;
	        StringTokenizer st;

	        public MyScanner() {
	            br = new BufferedReader(new InputStreamReader(System.in));
	        }

	        String next() {
	            while (st == null || !st.hasMoreElements()) {
	                try {
	                    st = new StringTokenizer(br.readLine());
	                } catch (IOException e) {
	                    e.printStackTrace();
	                }
	            }
	            return st.nextToken();
	        }

	        int nextInt() { return Integer.parseInt(next()); }
	        long nextLong() { return Long.parseLong(next()); }
	        double nextDouble() { return Double.parseDouble(next()); }

	        String nextLine(){
	            String str = "";
	            try {
	                str = br.readLine();
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            return str;
	        }
	    }
	    //--------------------------------------------------------
	}