0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

C - The 80/20 Rule

https://codeforces.com/gym/103698/submission/157277011
This commit is contained in:
Baoshuo Ren 2022-05-15 16:39:31 +08:00
parent fb6689946b
commit 64f36cd111
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

43
Gym/103698/C/C.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <algorithm>
#include <iomanip>
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, a[N], sum[N];
double ans_a, ans_b;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
std::sort(a + 1, a + 1 + n, std::greater<int>());
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + a[i];
}
ans_a = 100.0 * 1 / n;
ans_b = 1.0 * sum[1] * 100 / sum[n];
for (int i = 2; i <= n; i++) {
if (1.0 * sum[i] * 100 / sum[n] - 100.0 * i / n >= ans_b - ans_a) {
ans_a = 100.0 * i / n;
ans_b = 1.0 * sum[i] * 100 / sum[n];
}
}
cout << std::fixed << std::setprecision(2) << ans_a << ' '
<< std::fixed << std::setprecision(2) << ans_b << endl;
return 0;
}