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;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
pair<int, int> a[n];
for(int i = 0; i < n; i++) {
cin >> a[i].second >> a[i].first;
if(a[i].first == -1) a[i].first = 1e9;
}
sort(a, a+n);
double dp[n+1][k+1][k+1];
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= k; j++) {
for(int m = 0; m <= k; m++) {
if(m == 0 && i == 0 && j == 0) dp[i][j][m] = 0;
else if(i == 0 || i < m || i < j || m < j) dp[i][j][m] = 1e9;
else if(j == 0) dp[i][j][m] = min(dp[i-1][j][m-1] + a[i-1].second*1.0/(j+1), dp[i-1][j][m]);
else dp[i][j][m] = min(dp[i-1][j][m-1] + a[i-1].second*1.0/(j+1), min(dp[i-1][j-1][m-1] + a[i-1].first*1.0/j, dp[i-1][j][m]));
}
}
}
double res = 1e9;
for(int i = 0; i <= k; i++) res = min(res, dp[n][i][k]);
cout << fixed << setprecision(5) << res;
}
# | 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... |