This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
template<class T> using V = vector<T>;
const double eps = 1e-9;
int main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(15);
int N, K; cin >> N >> K;
V<int> A(N), B(N);
for(int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
if (B[i] == -1) B[i] = int(1e9);
}
double ans = double(1e9);
for(int c = 0; c <= N; c++) {
V<int> BI(N); iota(begin(BI), end(BI), 0);
sort(begin(BI), end(BI), [&](int i, int j) {
return B[i] < B[j];
});
V<int> AI; for(int i = c; i < N; i++) AI.push_back(BI[i]);
sort(begin(AI), end(AI), [&](int i, int j) {
return A[i] < A[j];
});
V<int> ord;
double res = 0;
for(int i = 0; i < c; i++) {
// cout << BI[i] << " " << B[BI[i]] << endl;
res += double(B[BI[i]]) / double(i + 1);
}
for(int i = 0; i < K - c; i++) {
// cout << AI[i] << " " << A[AI[i]] << endl;
res += double(A[AI[i]]) / double(c + 1);
}
// cout << c << " " << res << endl;
if (res+eps < ans) ans = res;
}
cout << ans << nl;
return 0;
}
# | 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... |