This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using dbl = double;
int main() {
int n;
cin >> n;
vector <pair <dbl, dbl>> nums(n);
for (int i = 0; i < n; i++)
cin >> nums[i].first >> nums[i].second;
dbl ans = 0;
for (int i = 0; i < (1 << n); i++) {
dbl l = 0;
vector <dbl> pts;
for (int j = 0; j < n; j++) {
if (i & (1 << j))
l += nums[j].first;
else
pts.push_back(nums[j].second);
}
sort(pts.begin(), pts.end(), greater <dbl> ());
int cnt = __builtin_popcount(i);
dbl r = 0;
for (auto j : pts) {
r += j;
cnt++;
if (r - l >= 0.00000000001)
break;
}
if (min(l, r) - cnt - ans > 0.00000000001)
ans = min(l, r) - cnt;
}
cout << fixed << setprecision(4) << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |