Submission #1364125

#TimeUsernameProblemLanguageResultExecution timeMemory
1364125edoLet's Win the Election (JOI22_ho_t3)C++20
100 / 100
194 ms2404 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  double ans = 1e18;
  vector<pair<double, double>> s(n);
  for (auto &[b, a] : s) {
    cin >> a >> b;
    if (b == -1)
      b = 1e9;
  }
  ranges::sort(s);
  for (int c = 0; c <= k; ++c) {
    int need = k - c;
    vector dp(n + 1, vector<double>(need + 1, 1e18));
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
      auto [b, a] = s[i];
      for (int j = 0; j <= need; ++j) {
        if (dp[i][j] > 1e17)
          continue;
        if (j < need) {
          dp[i + 1][j + 1] =
              min(dp[i + 1][j + 1], dp[i][j] + double(a) / double(c + 1));
        }
        double cost = 0;
        int use = i - j;
        if (use < c)
          cost = double(b) / double(use + 1);

        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cost);
      }
    }
    ans = min(ans, dp[n][need]);
  }
  cout << setprecision(12) << ans;
  return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...