# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1135106 | Unforgettablepl | Sandcastle 2 (JOI22_ho_t5) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long double double;
const int INF = 1e10;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,k;
cin >> n >> k;
vector<pair<int,int>> arr(n);
for(auto&[a,b]:arr){cin>>b>>a;if(a==-1)a=INF;}
sort(arr.begin(), arr.end());
arr.insert(arr.begin(),{0,0});
vector DP(n+1,vector(n+1,vector(n+1,(ld)INF)));
DP[0][0][0]=0;
auto solve = [&](ld x) {
for(int i=1;i<=n;i++) {
for(ld j=0;j<=x;j++) {
DP[i][i][j]=INF;
if(j)DP[i][i][j]=min(DP[i][i][j],DP[i-1][i-1][j-1]+(arr[i].first)/(j));
DP[i][i][j]=min(DP[i][i][j],DP[i-1][i-1][j]+(arr[i].second)/(x+1));
}
for(ld j=x;j<=i;j++) {
if(j!=i)DP[i][j][x]=INF;
if(j)DP[i][j][x]=min(DP[i][j][x],DP[i-1][j-1][x]+(arr[i].second)/(x+1));
DP[i][j][x]=min(DP[i][j][x],DP[i-1][j][x]);
}
}
return DP[n][k][x];
};
ld ans = INF;
for(int x=0;x<=k;x++)ans=min(solve(x),ans);
cout << setprecision(10) << ans << '\n';
}