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 double INF = 1.0 / 0.0;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector< pair<int, int> > states(n);
for (int i = 0; i < n; i++) {
cin >> states[i].second >> states[i].first;
if (states[i].first == -1) states[i].first = 0x3f3f3f3f;
}
sort(states.begin(), states.end());
auto solve = [&](int m) {
vector< vector<double> > dp(n + 1, vector<double>(k - m + 1, INF));
dp[0][0] = 0.0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= k - m; j++) {
if (j < k - m) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + (double) states[i].second / (m + 1));
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (i - j >= m ? 0.0 : (double) states[i].first / (i - j + 1)));
}
}
return dp[n][k - m];
};
int l = 0, r = k;
while (l < r - 2) {
//cout << l << ' ' << r << endl;
int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
double x1 = solve(m1), x2 = solve(m2);
if (x1 >= x2) l = m1;
if (x1 <= x2) r = m2;
}
double ans = INF;
for (int i = l; i <= r; i++) ans = min(ans, solve(i));
cout << fixed << setprecision(10) << 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... |