This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
auto solve = [&]() {
int n, k;
cin >> n >> k;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if (b[i] == -1) {
b[i] = 1e9;
}
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](auto i, auto j) {
return pair(b[i], a[i]) < pair(b[j], a[j]);
});
// dp[i][votes][coord]
double ans = 1e9;
for (int x = 0; x <= k; x++) {
vector dp(k + 1, vector<double>(x + 1, 1e9)), ndp(dp);
dp[0][0] = 0;
for (auto i : ord) {
ndp = dp;
for (int v = 0; v < k; v++) {
for (int c = 0; c <= x; c++) {
dp[v + 1][c] = min(dp[v + 1][c], ndp[v][c] + 1.0 * a[i] / (x + 1));
if (c < x) {
dp[v + 1][c + 1] = min(dp[v + 1][c + 1], ndp[v][c] + 1.0 * b[i] / (c + 1));
}
}
}
}
ans = min(ans, dp[k][x]);
}
cout << fixed << setprecision(9) << ans << '\n';
};
solve();
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... |