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;
int n, k, bbs=0;
int a[505], b[505];
vector<int> sA, sB;
bool vis[505];
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> k;
for(int i=0;i<n;i++) {
cin >> a[i] >> b[i];
sA.emplace_back(i);
if(b[i] != -1) sB.emplace_back(i);
bbs += (b[i] != -1);
}
sort(sA.begin(), sA.end(), [&](int i, int j){
return a[i] <= a[j];
});
sort(sB.begin(), sB.end(), [&](int i, int j){
return b[i] <= b[j];
});
long double ans, cans = 1e18;
for(int bs=0;bs<=min(bbs, k);bs++) {
memset(vis, 0, sizeof vis);
int cnt = 0;
ans = 0;
for(int i=0;i<bs;i++) {
cnt++;
vis[sB[i]] = 1;
ans += 1.00*b[sB[i]]/(i+1);
}
for(int i=0;i<n&&cnt!=k;i++) {
if(vis[sA[i]]) continue;
cnt++;
ans += 1.00*a[sA[i]]/(bs+1);
}
if(cnt != k) continue;
cans = min(cans, ans);
}
cout << fixed << setprecision(10) << cans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |