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;
#define ll long long
#define ar array
typedef pair<int, int> pi;
const int mxN = 505, M = 1e9+7;
int n, k;
pair<int, int> a[mxN];
double dp[mxN][mxN];
int main(){
#ifdef _DEBUG
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
cout << fixed << setprecision(12);
cin >> n >> k;
for(int i = 0; i<n; ++i){
cin >> a[i].first >> a[i].second;
if(a[i].second == -1) a[i].second = 1e8;
}
sort(a, a+n, [&](const pi &a, const pi &b){
return a.second < b.second;
});
double ret = 1e9;
for(int i = 0; i<=k; ++i){
for(int j = 0; j<=k-i; ++j){
dp[0][j] = 1e9;
}
dp[0][0] = 0;
for(int j = 1; j<=n; ++j){
for(int b = 0; b<=k-i; ++b){
int ord = j-b;
dp[j][b] = dp[j-1][b] + (1<=ord && ord <= i ? 1.0 * a[j-1].second / ord : 0);
if(b){
dp[j][b] = min(dp[j][b], dp[j-1][b-1] + 1.0*a[j-1].first / (i+1));
}
}
}
ret = min(ret, dp[n][k-i]);
}
cout << ret;
}
# | 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... |