AcWing 1235. 付账问题
原题链接
中等
作者:
wjie
,
2020-07-02 19:35:13
,
所有人可见
,
阅读 503
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 5e5 + 5;
double arr[N], avg, res;
int main()
{
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i)
scanf("%lf", &arr[i]);
sort(arr, arr+n);
int idx = 0;
double avg = m * 1.0 / n;
double shouldPay = avg;
while (idx < n && arr[idx] < shouldPay)
{
// cout << shouldPay << endl;
res += pow(arr[idx]-avg, 2);
m -= arr[idx];
shouldPay = m * 1.0 / (n - (++idx));
}
res += (n - idx) * pow(shouldPay - avg, 2);
res = sqrt(res / n);
printf("%.4lf", res);
return 0;
}