#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 + 10 < 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;
}
for (int i = bot + 1; i < top; i++) {
ans = min(ans, solve(n, k, a, i));
}
cout << setprecision(10) << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2340 KB |
Output is correct |
2 |
Correct |
32 ms |
2364 KB |
Output is correct |
3 |
Correct |
40 ms |
2360 KB |
Output is correct |
4 |
Correct |
24 ms |
2296 KB |
Output is correct |
5 |
Correct |
20 ms |
2364 KB |
Output is correct |
6 |
Correct |
34 ms |
2340 KB |
Output is correct |
7 |
Correct |
21 ms |
2364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |