#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
#define len(v) (int)((v).size())
const int inf = 1e9;
inline void solve(){
int n, k;
cin >> n >> k;
vector<pair<ll, ll>> a(n);
for (int i = 0; i < n; ++i){
cin >> a[i].first >> a[i].second;
}
sort(a.begin(), a.end(), [&](pair<int, int> p1, pair<int, int> p2){
if (p1.second == -1 && p2.second == -1) return false;
if (p1.second == -1 || p2.second == -1) return p1.second != -1;
return p1.second < p2.second;
});
auto calc = [&](int l){
vector<vector<vector<ld>>> dp(n + 1, vector<vector<ld>>(l + 1, vector<ld>(k + 1, 1e100)));
dp[0][0][0] = 0;
for (int i = 0; i < n; ++i){
for (int j = 0; j <= l; ++j){
for (int f = 0; f <= k; ++f){
dp[i + 1][j][f] = dp[i][j][f];
}
}
if (a[i].second != -1){
for (int j = 0; j < l; ++j){
for (int f = 0; f < k; ++f){
dp[i + 1][j + 1][f + 1] = min(dp[i + 1][j + 1][f + 1], dp[i][j][f] + a[i].second / (ld)(j + 1));
}
}
}
for (int j = 0; j <= l; ++j){
for (int f = 0; f < k; ++f){
dp[i + 1][j][f + 1] = min(dp[i + 1][j][f + 1], dp[i][j][f] + a[i].first / (ld)(l + 1));
}
}
}
return dp[n][l][k];
};
int li = -1, ri = n + 2;
while (ri - li > 3){
int m1 = (li * 2 + ri) / 2;
int m2 = (li + ri * 2) / 2;
ld ans1 = calc(max(min(m1, n), 0));
ld ans2 = calc(max(min(m2, n), 0));
if (ans2 > ans1){
li = m1;
}
else{
ri = m2;
}
}
ld ans = 1e100;
for (int i = -50; i < 50; ++i){
ans = min(ans, calc(max(min(li - i, n), 0)));
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout.precision(60);
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... |