CodeCraft-19 and Codeforces Round #537 (Div. 2) B. Average Superhero Gang Power
先排序,直接暴力把前i个数删掉求最大平均值(0<=i<=min(n-1,m)),然后取最大即可
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+10;
int a[maxn],n,k,m;
ll pre[maxn],sum;
double ans;
int main()
{
scanf("%d%d%d",&n,&k,&m);
for(int i=1;i<=n;i++) scanf("%d",&(a[i]));
sort(a+1,a+n+1);
for(int i=1;i<=n;i++) pre[i]=pre[i-1]+1LL*a[i];
for(int i=0;i<=min(m,n-1);i++)
{
sum=pre[n]-pre[i]+min(1LL*k*(n-i),1LL*(m-i));
ans=max(ans,1.0*sum/(n-i));
}
printf("%lf\n",ans);
return 0;
}