This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//JOI 2022 Final round
#include<bits/stdc++.h>
using namespace std;
const double INF=1e9+7;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(100);
int n, k;
cin >> n >> k;
vector<int> a(n);
vector<int> b(n);
for(int i=0; i<n; i++){
cin >> a[i] >> b[i];
if(b[i]==-1) b[i]=INF;
}
vector<int> sorted(n);
iota(sorted.begin(), sorted.end(), 0);
sort(sorted.begin(), sorted.end(), [&](int i, int j){
return b[i]<b[j];
});
double ans=INF;
for(int c=0; c<=k; c++){
vector<vector<double> > dp(n+1, vector<double> (k+1, INF));
dp[0][0]=0;
for(int i=0; i<n; i++){
for(int j=0; j<= min(i+1, k); j++){
int x=i+1-j;
int ind=sorted[i];
if(0<x && x<=c){
dp[i+1][j] = dp[i][j] + (double)b[ind]/(double)x;
}
else if(c<x){
dp[i+1][j] = dp[i][j];
}
if(0<j){
dp[i+1][j] = min(dp[i+1][j], dp[i][j-1] + (double)a[ind]/(double)(c+1));
}
}
}
ans = min(ans, dp[n][k-c]);
}
cout << 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... |