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;
typedef long double ld;
int N, K;
vector<pair<ld, ld>> v;
ld solve(ld collaborators){
vector<vector<ld>> dp(K+1, vector<ld>(collaborators + 1, 1e18));
dp[0][0] = 0;
for(int i = 0; i < N; i++){
for(int elem = K - 1; elem >= 0; elem--){
for(int j = collaborators; j >= 0; j--){
if(j != collaborators) dp[elem+1][j+1] = min(dp[elem+1][j+1], dp[elem][j] + v[i].first / (j+1.0));
dp[elem+1][j] = min(dp[elem+1][j], dp[elem][j] + v[i].second / (collaborators+1.0));
}
}
}
return dp[K][collaborators];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> K;
v.resize(N);
for(int i = 0; i < N; i++){
cin >> v[i].second >> v[i].first;
if(v[i].first == -1) v[i].first = 1e9;
}
sort(v.begin(), v.end());
ld ans = 7e18;
int lo = 0;
int hi = K - 1;
while(lo <= hi){
int mid = (lo + hi) / 2;
ld collab = mid;
ld ans1 = solve(collab);
ans = min(ans, ans1);
if(mid == hi){
hi = mid - 1;
}else{
ld ans2 = solve(collab + 1);
ans = min(ans, ans2);
if(ans2 < ans1){
lo = mid + 1;
}else hi = mid - 1;
}
}
cout << fixed << setprecision(8) << 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... |