Codeforces Round #664 (Div. 2)练习

Codeforces Round #664 (Div. 2)

D

题目地址

把数按与 \(m\) 的大小分为两类。假设我们选择了 \(i\) 个不超过 \(m\) 的数,那么就可以选 \(\lceil \frac{n-i-1}{d+1} \rceil + 1\) 个超过 \(m\) 的数。枚举 \(i\) 即可求出最大值。

Talk is cheap.Show me the code.

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read() {
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
	return x * f;
}
const int N = 1e5+7;
int n,d,m,ans;
int a[N],s1[N],s2[N];
bool cmp(int x,int y) {
	return x > y;
}
signed main()
{
	n = read(), d = read(), m = read();
	for(int i=1;i<=n;++i) a[i] = read();
	sort(a+1, a+1+n, cmp);
	int q = 0;
	for(int i=1;i<=n+1;++i)
		if(a[i] <= m) {
			q = i - 1; break;
		}
	for(int i=1;i<=q;++i) s1[i] = s1[i-1] + a[i];
	for(int i=q+1;i<=n;++i) s2[i-q] = s2[i-q-1] + a[i];
	for(int i=0;i<=n;++i) {
		ans = max(ans,s1[(n-i-1)/(d+1)+1]+s2[i]);
	}
	printf("%lld\n",ans);
	return 0;
}
/*
5 2 11
8 10 15 23 5
 
48
*/

posted @ 2020-08-18 13:23  基地AI  阅读(108)  评论(0编辑  收藏  举报