#include <algorithm>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
const int maxn = 505;
const int INF = 1e9;
int n, k;
double a[maxn];
double b[maxn];
pair<double, double> p[maxn];
double dp[maxn][maxn];
double f(int s, int cnt) {
vector<double> v;
for (int i = s; i < n; i++) {
v.push_back(a[i]);
}
if ((int)v.size() < cnt) return INF;
sort(v.begin(), v.end());
double rtn = 0;
for (int i = 0; i < cnt; i++) {
rtn += v[i];
}
return rtn;
}
double myDP(int x) {
dp[0][0] = a[0] / (x + 1);
dp[0][1] = b[0] / 1;
for (int j = 2; j <= x; j++) dp[0][j] = INF;
for (int i = 1; i < n; i++) {
dp[i][0] = dp[i - 1][0] + a[i] / (x + 1);
for (int j = 1; j <= x; j++) {
if (j > i + 1) {
dp[i][j] = INF;
} else {
double A = dp[i - 1][j] + a[i] / (x + 1);
double B = dp[i - 1][j - 1] + b[i] / j;
dp[i][j] = min(A, B);
}
}
}
double rtn = INF;
for (int i = 0; i < n; i++) {
rtn = min(rtn, dp[i][x] + f(i + 1, k - x) / (x + 1));
}
return rtn;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if (b[i] == -1) b[i] = INF;
p[i] = {b[i], a[i]};
}
sort(p, p + n);
for (int i = 0; i < n; i++) {
b[i] = p[i].first;
a[i] = p[i].second;
}
double an = INF;
for (int x = 0; x <= k; x++) {
an = min(an, myDP(x));
}
cout << fixed << setprecision(15) << an << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1616 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |