#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
const bool Multitest = 0;
const int N = 505; const ll offset = 1e9;
int n, k;
struct Type
{
ld x, y;
}; Type a[N], b[N];
bool cmp1(Type a, Type b)
{
return a.y < b.y || (a.y == b.y && a.x < b.x);
}
ld dp[N][N], f[N];
void minimize(ld& a, ld b)
{
if(a > b) a = b;
}
ld cal(int p)
{
if(f[p] > 0) return f[p];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= k - p; ++j) {
dp[i][j] = 1e18;
}
}
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= min(i, k - p); ++j) {
int x = i - j - 1;
if (j > 0) {
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1.0 * a[i].x / (p + 1));
}
dp[i][j] = min(dp[i][j], dp[i - 1][j] + (x < p ? 1.0 * a[i].y / (x + 1) : 0));
}
}
return f[p] = dp[n][k - p];
}
void work()
{
cin >> n >> k;
for(int i = 1 ; i <= n ; i++)
{
cin >> a[i].x >> a[i].y;
if(a[i].y == -1) a[i].y = 1e9;
// f[i] = -1;
}
for(int i = 0 ; i <= n ; i++) f[i] = -1;
sort(a + 1, a + 1 + n, cmp1);
ld ans = 1e18;
// cerr << "dm";
//
// cout << cal(2);
////
// return;
int l = 0, r = n - 1, pos = n;
while(l <= r)
{
int mid = (l + r) >> 1;
if(cal(mid) >= cal(mid + 1)) l = mid + 1, pos = mid;
else r = mid - 1;
}
cout << setprecision(9) << fixed << f[pos];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int q = 1;
if(Multitest) cin >> q;
while(q--) work();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |