「Luogu P5602」小E与美食
题目链接
\(Solution\)
这道题只需要枚举吃\(k\)个美食,最后在取前\(k\)大的美味值。对于每个算出答案后取\(max\)
\(Code\)
#include<bits/stdc++.h>
#define int __int128
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
return f*x;
}
int a[3000001];
int sum[3000001];
bool cmp(int a,int b){
return a>b;
}
main(){
int n=read();
long double maxx=0;
for(int i=1;i<=n;i++)
a[i]=read();
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
sum[i]=sum[i-1]+a[i];
for(int i=1;i<=n;i++)
maxx=max(maxx,(long double)sum[i]*1.0/i*sum[i]);
printf("%0.8Lf",maxx);
}