#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
pii arr[505];
int target=0;
int n,k;
bool visited[505][505];
ld memo[505][505];
int cnt=0;
ld dp(int index, int take){
//cout << index << " " << take << "\n";
if(index==n){
//cout << take << " " << k << " " << index-take << " " << target << endl;
if(k-take!=target) return 1e12;
return 0.0;
}
if(visited[index][take]) return memo[index][take];
ld ans=1e12;
ans=min(ans,dp(index+1,take+1)+(ld)arr[index].second/(ld)(target+1));
//cout << index-take << " " << target << endl;
if(index-take<target) ans=min(ans,dp(index+1,take)+(ld)arr[index].first/(ld)(index-take+1)); //forced to do something
else{
//show(trigger,1);
ans=min(ans,dp(index+1,take)); //do nothing
}
//cout << index << " " << take << ' ' << ans << endl;
visited[index][take]=true;
return memo[index][take]=ans;
}
void solve(){
cin >> n >> k;
for(int x=0;x<n;x++){
cin >> arr[x].second >> arr[x].first;
if(arr[x].first==-1) arr[x].first=1e8;
else cnt++;
}
sort(arr,arr+n);
ld ans=1e15;
for(int x=0;x<=min(cnt,k);x++){
target=x;
memset(visited,0,sizeof(visited));
ans=min(ans,dp(0,0));
//cout << ans << endl;
}
cout << fixed << setprecision(10) << ans << "\n";
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("in.txt","r",stdin);
//freopen("in.txt","w",stdout);
int t=1;
//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... |