#include <bits/stdc++.h>
using namespace std;
using ld = long double;
const int MAXN = 510;
const ld INF = 1e18;
pair<ld, ld> p[MAXN];
ld dp_1[MAXN][MAXN], dp_2[MAXN][MAXN];
int main(){
  cin.tie(0)->sync_with_stdio(0);
  int n, K; cin >> n >> K;
  for(int i=1; i<=n; i++){
    cin >> p[i].second >> p[i].first;
    if(p[i].first == -1) p[i].first = INF;
  }
  sort(p + 1, p + n + 1);
  ld ans = INF;
  for(int x=1; x<=(n + 1); x++){
    for(int k=0; k<=x; k++) dp_1[0][k] = INF;
    
    for(int j=0; j<=K; j++) dp_2[0][j] = INF;
    dp_1[0][1] = 0;
    for(int i=1; i<=n; i++){
      // se ainda nao tenho x, nao faz sentido ignorar o estado
      for(int k=0; k<=x; k++){
        dp_1[i][k] = dp_1[i - 1][k] + p[i].second / x;
        if(k > 0) dp_1[i][k] = min(dp_1[i][k], dp_1[i - 1][k - 1] + p[i].first / (k - 1));
      }
      // se já tenho x, não faz sentido ficar gastando com b
      dp_2[0][0] = dp_1[0][x];
      for(int j=0; j<=K; j++){
        dp_2[i][j] = dp_2[i - 1][j];
        if(j > 0) dp_2[i][j] = min(dp_2[i][j], dp_2[i - 1][j - 1] + p[i].second / x);
        if(j == i) dp_2[i][j] = min(dp_2[i][j], dp_1[i][x]);
      }
    }
    ans = min(ans, dp_2[n][K]);
    
  }
  cout << fixed << setprecision(15) << ans << "\n";
  return 0;
}
| # | 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... |