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;
const int N = 500 + 3;
const double inf = 1e6 + 3;
int n, k, a[N], b[N], p[N];
double f[N][N];
double calc(int m) {
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= i; ++j) {
f[i][j] = inf;
if (j) f[i][j] = min(f[i][j], f[i - 1][j - 1] + (double)a[p[i]] / (m + 1));
if (j < i) {
if (i - j - 1 < m) f[i][j] = min(f[i][j], f[i - 1][j] + (double)b[p[i]] / (i - j));
else f[i][j] = min(f[i][j], f[i - 1][j]);
}
}
}
return f[n][k - m];
}
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
if (b[i] == -1) b[i] = INT_MAX;
}
iota(p + 1, p + n + 1, 1);
sort(p + 1, p + n + 1, [&](int i, int j) {
if (b[i] != b[j]) return b[i] < b[j];
return a[i] < a[j];
});
double ans = inf;
for (int i = 0; i <= k; ++i)
ans = min(ans, calc(i));
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << setprecision(15) << fixed;
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... |