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;
double solve(int n, int k, vector<pair<int, int>> &a, int totalB) {
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 1e9));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int As = 0; As <= min(i - 1, k - totalB); As++) {
int Bs = min(totalB, i - 1 - As);
if (As < k - totalB) {
double d = a[i].first;
dp[i][As + 1] = min(dp[i][As + 1], dp[i - 1][As] + d / (totalB + 1));
}
if (Bs < totalB) {
double d = a[i].second;
dp[i][As] = min(dp[i][As], dp[i - 1][As] + d / (Bs + 1));
}
else {
dp[i][As] = min(dp[i][As], dp[i - 1][As]);
}
}
}
return dp[n][k - totalB];
}
int main() {
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<pair<int, int>> a(n + 1, {0, 0});
for (int i = 1; i <= n; i++) {
cin >> a[i].second >> a[i].first;
if (a[i].first == -1) a[i].first = 1e9;
}
sort(a.begin(), a.end());
for (int i = 1; i <= n; i++) {
swap(a[i].first, a[i].second);
}
double ans = 1e9;
int bot = 0, top = k;
while (bot + 2 < top) {
int m1 = (bot * 2 + top) / 3;
int m2 = (bot + top * 2) / 3;
double ans1 = solve(n, k, a, m1);
double ans2 = solve(n, k, a, m2);
ans = min(ans, min(ans1, ans2));
if (ans1 > ans2) bot = m1;
else top = m2;
}
cout << setprecision(10) << ans << endl;
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... |