#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[2][N][N], f[N];
void minimize(ld& a, ld b)
{
if(a > b) a = b;
}
ld cal(int p)
{
for(int i = 0 ; i < 2 ; i++)
{
for(int j = 0 ; j <= n ; j++)
{
for(int cnt = 0 ; cnt <= n + 1 ; cnt++)
{
dp[i][j][cnt] = 1e18;
}
}
}
dp[0][0][1] = 0;
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j <= k && j <= i ; j++)
{
for(int cnt = 1 ; cnt <= j + 1 && cnt <= p; cnt++)
{
minimize(dp[1][j][cnt], dp[0][j][cnt]);
minimize(dp[1][j + 1][cnt], dp[0][j][cnt] + a[i + 1].x / p);
minimize(dp[1][j + 1][cnt + 1], dp[0][j][cnt] + a[i + 1].y / cnt);
//
// cout << i << ' ' << j << ' ' << cnt << ' ' << dp[i][j][cnt] << '\n';
}
}
swap(dp[0], dp[1]);
for(int j = 0 ; j <= min(k, i) + 1 ; j++)
{
for(int cnt = 0 ; cnt <= min(j + 1, p) + 1 ; cnt++)
{
dp[1][j][cnt] = 1e18;
}
}
}
return f[p] = dp[0][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;
}
sort(a + 1, a + 1 + n, cmp1);
ld ans = 1e18;
// cerr << "dm";
//
// cout << cal(1);
////
// return;
int l = 1, r = n, pos = n + 1;
while(l <= r)
{
int mid = (l + r) >> 1;
if(cal(mid) <= cal(mid + 1)) r = mid - 1, pos = mid;
else l = 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... |