#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, 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][mn];
void solve(){
cin >> n >> K;
for(int i = 1; i <= n; i++){
cin >> e[i].a >> e[i].b;
e[i].b = (e[i].b == -1 ? inf : e[i].b);
}
sort(e + 1, e + n + 1);
fill(&dp[0][0][0], &dp[0][0][0] + mn * mn * mn, inf);
dp[0][1][0] = 0;
double ans = inf;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= K; j++){
for(int k = j - 1; k <= K; k++){
dp[i][j][k] = min({dp[i - 1][j - 1][k - 1] + (double) e[i].b / (double) (j - 1),
dp[i - 1][j][k - 1] + (double) e[i].a / (double) j,
dp[i - 1][j][k]});
if(k == K){
ans = min(ans, dp[i][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... |