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 main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if (b[i] == -1) {
b[i] = (int) 1e9;
}
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
if (b[i] != b[j]) {
return b[i] < b[j];
} else {
return a[i] < a[j];
}
});
vector<int> new_a(n);
vector<int> new_b(n);
for (int i = 0; i < n; i++) {
new_a[i] = a[order[i]];
new_b[i] = b[order[i]];
}
a = new_a;
b = new_b;
const double inf = 1e9;
double ans = inf;
for (int s = 0; s <= k; s++) {
vector<double> dp(n + 1, inf);
dp[0] = 0;
for (int i = 0; i < n; i++) {
vector<double> new_dp(n + 1, inf);
for (int j = 0; j <= min(k - s, i); j++) {
if (i - j < s) {
new_dp[j] = min(new_dp[j], dp[j] + (double) (b[i] + 0.000) / (double) (i - j + 1));
} else {
new_dp[j] = min(new_dp[j], dp[j]);
}
new_dp[j + 1] = min(new_dp[j + 1], dp[j] + (double) (a[i] + 0.000) / (double) (s + 1));
}
swap(dp, new_dp);
if (i + 1 >= k) {
ans = min(ans, dp[k - s]);
}
}
}
cout << fixed << setprecision(3) << ans << '\n';
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... |