#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 = 1e9;
int n, k;
struct Megumi{
int a, b;
bool operator<(const Megumi& other) const{
if(b == other.b) return a < other.a;
return b < other.b;
}
} e[mn];
double dp[mn][mn];
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> e[i].a >> e[i].b;
if(e[i].b == -1) e[i].b = inf;
}
sort(e + 1, e + n + 1);
double ans = inf;
for(int num = 0; num <= k; num++){
for(int i = 0; i <= n; i++){
for(int j = 0; j <= k; j++){
dp[i][j] = inf;
}
}
dp[0][0] = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= i; j++){
if(j > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1.0 * e[i].a / (num + 1));
if(i - j <= num) dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1.0 * e[i].b / (i - j));
else dp[i][j] = min(dp[i][j], dp[i - 1][j]);
}
}
ans = min(ans, dp[n][k - num]);
}
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... |