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;
double dp[509];
pair<double, double> t[509];
double w = 1000000000000000000;
int n, k;
bool cmp(pair<double, double> a, pair<double, double> b){
return a.second < b.second;
}
double wynik(int x){
for(int i = 0; i <= n; i++){
dp[i] = 1000000000000000000;
}
//vector<double>dp(k - x + 1, 1e9);
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].first / (double)(x + 1);
}
else {
dp[j] = 1e9;
}
if(0 < (i + 1) - j && (i + 1) - j <= x) {
dp[j] = min(dp[j], popdp + t[i].second / (double)((i + 1) - j));
}
else {
dp[j] = min(dp[j], popdp);
}
}
}
return dp[k - x];
}
int main(){
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
cin>>n>>k;
for(int i = 0; i < n; i++){
cin>>t[i].first>>t[i].second;
if(t[i].second == -1) t[i].second = 1000000000000000120;
}
sort(t, t + n, cmp);
for(int i = 0; i <= k; i++){
w = min(w, wynik(i));
}
cout<<fixed<<setprecision(9)<<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... |