#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 5e2 + 5;
pair<int, int> state[MAX];
double f[MAX][MAX][MAX];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> state[i].first >> state[i].second;
sort(state + 1, state + n + 1, [](const pair<int, int> &a, const pair<int, int> &b) -> bool {
if (a.second != -1 && b.second != -1) {
return a.second < b.second;
}
return a.second > b.second;
});
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n + 1; j++) {
for (int z = 0; z <= k; z++) {
f[i][j][z] = 1e9;
}
}
}
f[0][1][0] = 0.0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i + 1; j++) {
for (int z = 1; z <= k; z++) {
f[i][j][z] = min(f[i - 1][j][z - 1] + (1.0 * state[i].first / j), f[i - 1][j][z]);
if (j > 1 && state[i].second != -1) {
f[i][j][z] = min(f[i][j][z], f[i - 1][j - 1][z - 1] + (1.0 * state[i].first / (j - 1)) + (1.0 * (state[i].second - state[i].first) / (j - 1)));
}
}
}
}
double ans = 1e9;
for (int j = 1; j <= n + 1; j++) {
ans = min(ans, f[n][j][k]);
}
cout << fixed << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
586 ms |
996432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |