#include <bits/stdc++.h>
// Author: Kazuki_Will_Win_VOI_8703
#define fi first
#define se second
#define pii pair<int, int>
#define ll long long
using namespace std;
const int mn = 5e2 + 5, lg2 = 20, mbit = (1 << 20) + 1, mm = 5e3 + 5;
const double INF = 1e100;
int n, K;
struct Megumi{
int a, b;
bool operator<(const Megumi& other) const{
int bb = (b == -1 ? INT_MAX : b);
int ob = (other.b == -1 ? INT_MAX : other.b);
if(bb == ob) return a < other.a;
return bb < ob;
}
} e[mn];
double dp[2][mn][mn];
void solve(){
cin >> n >> K;
for(int i = 1; i <= n; i++){
cin >> e[i].a >> e[i].b;
}
sort(e + 1, e + n + 1);
for(int t = 0; t < 2; t++){
for(int j = 0; j <= K; j++){
for(int k = 0; k <= K; k++){
dp[t][j][k] = INF;
}
}
}
dp[0][1][0] = 0.0;
double ans = INF;
for(int i = 1; i <= n; i++){
int cur = i & 1;
int pre = cur ^ 1;
for(int j = 0; j <= K; j++){
for(int k = 0; k <= K; k++){
dp[cur][j][k] = INF;
}
}
for(int j = 1; j <= K; j++){
for(int k = 0; k <= K; k++){
dp[cur][j][k] = min(dp[cur][j][k], dp[pre][j][k]);
if(k >= 1 && dp[pre][j][k - 1] < INF){
double cand = dp[pre][j][k - 1] + (double)e[i].a / (double)j;
if(cand < dp[cur][j][k]) dp[cur][j][k] = cand;
}
if(e[i].b != -1 && j >= 2 && k >= 1 && dp[pre][j - 1][k - 1] < INF){
double cand = dp[pre][j - 1][k - 1] + (double)e[i].b / (double)(j - 1);
if(cand < dp[cur][j][k]) dp[cur][j][k] = cand;
}
if(k == K && dp[cur][j][k] < ans) ans = dp[cur][j][k];
}
}
}
cout << setprecision(15) << fixed << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
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... |