P5602 小 E 与美食

(n-i+1) 相当于吃没事的个数 = 饱腹感

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

const int N = 3e5 + 7;

int n;
int a[N];

long long sum;  //!!
double maxn;


int main() {

	cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];

	sort(a+1,a+1+n);

	for(int i=n; i>=1; i--) {
		sum+=a[i];
		maxn=max(maxn,1.0*sum/(n-i+1)*1.0*sum);  //以防溢出 先除再乘  
	}
    cout<<setiosflags(ios::fixed)<<setprecision(8);
	cout<<maxn;

	return 0;

}
posted @ 2024-05-23 21:26  LTphy  阅读(38)  评论(0)    收藏  举报