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 ll = long long;
#define sz(x) (int)size(x)
#define all(x) (x).begin(), (x).end()
constexpr double inf = 1e18;
double pmin(double &a, double b){
return a = min(a, b);
}
int main(){
cin.tie(0)->sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<double> a(n), b(n);
for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
{
vector<int> ord(n);
for(int i = 0; i < n; i++) ord[i] = i;
sort(all(ord), [&](int i, int j){return b[i] < b[j];});
vector<double> a2(n), b2(n);
for(int i = 0; i < n; i++) a2[i] = a[ord[i]], b2[i] = b[ord[i]];
a = a2, b = b2;
}
double ans = inf;
for(int l = 0; l <= k; l++){
vector<vector<double>> dp(l+1, vector<double>(k-l+1, inf));
dp[0][0] = 0;
for(int i = 0; i < n; i++){
auto dp2 = dp;
for(int j = 0; j <= l; j++){
for(int h = 0; h <= k-l; h++){
if(j < l && b[i] > 0) pmin(dp2[j+1][h], dp[j][h] + b[i] / (1+j));
if(h < k-l) pmin(dp2[j][h+1], dp[j][h] + a[i] / (1+l));
}
}
swap(dp, dp2);
}
ans = min(ans, dp[l][k-l]);
}
cout << setprecision(6) << fixed << ans << "\n";
}
# | 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... |