#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define SS ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#pragma optimize("g", on)
#pragma GCC optimize("03")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#define int long long
#define all(x) x.begin(),x.end()
#define F first
#define S second
using namespace std;
// using namespace __gnu_pbds;
// #define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
const int LG = 20,N = 2e5+1,inf = 1e9,MOD = 998244353;
const double eps = 1e-9;
int T;
void solve() {
int n,k;
cin>>n>>k;
int a[n+1],b[n+1];
pair<int,int> p[n+1];
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
b[i]=(b[i]==-1 ? inf : b[i]);
p[i]={b[i],a[i]};
}
sort(p+1,p+n+1);
for(int i=1;i<=n;i++){
a[i]=p[i].S;
b[i]=p[i].F;
}
vector<vector<vector<double>>> dp(n+1,vector<vector<double>>(n+1,vector<double>(n+1,inf*1.0)));
dp[0][0][0]=0.0;
for(int i=1;i<=n;i++){
for(int j=1;j<=min(i,k);j++){
for(int c=0;c<=j;c++){
if(c) dp[i][j][c]=min(dp[i][j][c],dp[i-1][j-1][c-1] + (b[i]*1.0)/(c*1.0));
if(c!=j) dp[i][j][c]=min(dp[i][j][c],dp[i-1][j-1][c] + (a[i]*1.0)/((c+1)*1.0));
dp[i][j][c]=min(dp[i][j][c],dp[i-1][j][c]);
}
}
}
double ans=inf*1.0;
for(int c=0;c<=k;c++){
ans=min(ans,dp[n][k][c]);
}
cout<<fixed<<setprecision(6)<<ans;
return;
}
signed main() {
// freopen("deleg.in","r",stdin);
// freopen("deleg.out","w",stdout);
SS
int t = 1;
if (T) {
cin >> t;
}
while (t--) {
solve();
}
}
/*
*/
# | 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... |