#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 |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
2396 KB |
Output is correct |
2 |
Correct |
25 ms |
2356 KB |
Output is correct |
3 |
Correct |
25 ms |
2356 KB |
Output is correct |
4 |
Correct |
20 ms |
2356 KB |
Output is correct |
5 |
Correct |
18 ms |
2356 KB |
Output is correct |
6 |
Correct |
26 ms |
2344 KB |
Output is correct |
7 |
Correct |
18 ms |
2340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |