#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
const int maxn = 501;
ld A[501];
ld B[501];
ld dp[maxn+3][maxn+3];
ld dp_kth_small[maxn+3][maxn+3];
int n,k;
ld calc(int ile)
{
ld ans = 1e9;
rep(i,n+1) dp_kth_small[n+1][i] = 1e9;
dp_kth_small[n+1][0] = 0;
for(int i = n; i >= 1; i--)
{
rep2(d,0,n)
{
dp_kth_small[i][d] = dp_kth_small[i+1][d];
if(d != 0) dp_kth_small[i][d] = min(dp_kth_small[i][d],dp_kth_small[i+1][d-1] + A[i]/(ld)(ile+1));
}
}
dp[0][0] = 0;
rep2(i,1,n) dp[0][i] = 1e9;
if(ile == 0) ans = dp_kth_small[1][k];
rep2(i,1,n)
{
rep2(d,0,n)
{
dp[i][d] = min(dp[i-1][d] + A[i]/(ld)(ile+1),(k != 0 ? dp[i-1][d-1] + B[i]/(ld)d : 1e9));
if(d == ile) ans = min(ans,dp[i][d] + dp_kth_small[i+1][max(0,k-i)]);
}
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//random_start();
cin >> n >> k;
vector<pll> elms;
rep2(i,1,n)
{
cin >> A[i] >> B[i];
if(B[i] == -1) B[i] = 1e18;
elms.pb({B[i],A[i]});
}
sort(all(elms));
rep(i,n)
{
A[i+1] = elms[i].ss;
B[i+1] = elms[i].ff;
}
ld ans = 1e9;
rep2(ile,0,n)
{
ans = min(ans,calc(ile));
}
cout << fixed << setprecision(7) << ans << "\n";
}
# | 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... |