开始本来以为可以直接贪心的。。。最后还是得dp统计答案
①把大于m和小于等于m的分成2组降序求前缀和,小于等于m的size为cnt,大于的为tot
②将i从0枚举到cnt,指选择i个小于等于m的数(从大到小贪心),剩下n-i个数,再从其中选择(n-i+d)/(d+1)个禁言单元(每一次禁言消耗d+1天,但最后一个单元的禁言时间可以超过n,因此需要上取整)
③\(ans=max(ans,a[i] + (bigsiz > tot ? b[tot] : b[bigsiz]))\);
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int maxn = 1e5 + 10;
const int inf = 1e8;
ll mod = 1e9 + 7;
int cnt, tot;
void pre(vector<ll> &a,int n)
{
sort(a.begin() + 1, a.end(), greater<>());
for (int i = 1; i <= n; i++)
a[i] += a[i - 1];
}
int main()
{
//freopen("C:\\1.in", "r", stdin);
fastio;
ll n, m, d;
cin >> n >> d >> m;
vector<ll>a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++)
{
ll x;
cin >> x;
if (x <= m)a[++cnt] = x;
else b[++tot] = x;
}
pre(a, cnt);
pre(b, tot);
ll ans = 0;
for (int i = 0; i <= cnt; i++)
{
int bigsiz = (n - i + d) / (d + 1);//剩下的除d+1上取整
ans = max(ans, a[i] + (bigsiz > tot ? b[tot] : b[bigsiz]));
}
cout << ans;
return 0;
}