#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 = 1e18,MOD = 998244353;
const double eps = 1e-9;
int T;
int n,k;
int a[N],b[N];
double get(int x){
vector<vector<double>> dp(n+1,vector<double>(n+1,inf));
dp[0][0]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=i;j++){
if(j) dp[i][j]=min(dp[i][j],dp[i-1][j-1]+double(a[i])/double(x+1));
if(i-j<=x) dp[i][j]=min(dp[i][j],dp[i-1][j]+double(b[i])/double(i-j));
else dp[i][j]=min(dp[i][j],dp[i-1][j]);
}
}
return dp[n][k-x];
}
void solve() {
cin>>n>>k;
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;
}
double ans=inf;
for(int x=0;x<=k;x++){
ans=min(ans,get(x));
}
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();
}
}
/*
dp[i][j]=dp[i-1][j-1]+a[i]/(x+1)
i need to take i as cooperator only on prefix and do not skip any free numbers on prefix
i can take number on prefix if already numbers of non taken elements on prefix is less or equal tham x
so i can take number if i-j<=x
dp[i][j]=dp[i-1][j]+b[i]/(i-j);
*/
# | 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... |