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;
const long double INF = 1e18;
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
return b[i] < b[j];
});
vector<int> new_a(n), 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;
long double ans = INF;
for (int c = 0; c <= k; c++) {
vector dp(k + 1, vector<long double>(c + 1, INF));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
vector new_dp(n + 1, vector<long double>(c + 1, INF));
for (int j = 0; j <= k; j++) {
for (int l = 0; l <= c; l++) {
if (j + 1 <= k && l + 1 <= c && b[i] != -1) {
new_dp[j + 1][l + 1] = min(new_dp[j + 1][l + 1], dp[j][l] + (long double)b[i] / (l + 1));
}
if (j + 1 <= k) {
new_dp[j + 1][l] = min(new_dp[j + 1][l], dp[j][l] + (long double)a[i] / (c + 1));
}
new_dp[j][l] = min(new_dp[j][l], dp[j][l]);
}
}
dp = new_dp;
}
for (int i = k; i <= n; i++) {
ans = min(ans, dp[i][c]);
}
}
cout << ans << "\n";
}
int main() {
cout << fixed << setprecision(9);
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
# | 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... |