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>
#include <fstream>
using namespace std;
pair<double, double> t[509];
double dp[509];
int n, k;
double wynik(int x) {
for(int i = 0; i <= n; i++){
dp[i] = 1000000000000000000;
}
dp[0] = 0;
for(int i = 0; i < n; i++) {
for(int j = min(i + 1, k - x); j >= 0; j--) {
double popdp = dp[j];
if(j > 0) {
dp[j] = dp[j - 1] + t[i].second / (double)(x + 1);
}
else {
dp[j] = 1000000000000000000;
}
if(0 < (i + 1) - j && (i + 1) - j <= x) {
dp[j] = min(dp[j], popdp + t[i].first / (double)((i + 1) - j));
}
else {
dp[j] = min(dp[j], popdp);
}
}
}
return dp[k - x];
}
int main(){
cin>>n>>k;
for(int i = 1; i <= n; i++){
double a, b;
cin>>a>>b;
if(b == -1){
b = 1000000000000000000;
}
t[i - 1] = {b, a};
}
sort(t, t + n);
double w = 1000000000000000000;
for(int i = 0; i <= k; i++){
w = min(w, wynik(i));
}
cout<<fixed<<setprecision(5)<<w<<endl;
}
# | 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... |