#include<bits/stdc++.h>
using namespace std;
mt19937 rnd(51);
#define ll long long
#define pb push_back
#define ld long double
const int N = 510, INF = 1e9;
int a[N], b[N], n, k;
ld dp[N][N][N];
vector<int> ord;
ld solve(int cnt) {
dp[0][0][1] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
if (i == j) {
for (int k = 1; k <= i + 1; k++) {
dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k] + (ld)b[ord[i]] / (ld)k);
dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + (ld)a[ord[i]] / (ld)cnt);
}
} else {
dp[i + 1][j][cnt] = min(dp[i + 1][j][cnt], dp[i][j][cnt]);
dp[i + 1][j + 1][cnt] = min(dp[i + 1][j + 1][cnt], dp[i][j][cnt] + (ld)a[ord[i]] / (ld)cnt);
}
}
}
return dp[n][k][cnt];
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
dp[i][j][k] = INF;
}
}
}
cin >> n >> k;
ord.resize(n);
iota(ord.begin(), ord.end(), 0);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if (b[i] == -1) {
b[i] = INF;
}
}
sort(ord.begin(), ord.end(), [&](int i, int j){return b[i] < b[j] || (b[i] == b[j] && a[i] < a[j]);});
ld ans = INF;
for (int i = 1; i <= k + 1; i++) {
ans = min(ans, solve(i));
}
cout << setprecision(30) << fixed << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
781 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
781 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
796 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
796 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
796 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
774 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
781 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |