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;
using ld = long double;
const int N = 500;
ll dpm[N+5][N+5];
ld dp[N+5][N+5];
pair <int, int> a[N+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, k;
cin >> n >> k;
for(int i=1; i<=n; i++){
cin >> a[i].first >> a[i].second;
if(a[i].second == -1) a[i].second = 1005;
}
sort(a+1, a+1+n, [](pair <int, int> x, pair <int, int> y){ if(x.second == y.second) return x.first < y.first; return x.second < y.second; });
for(int j=1; j<=n; j++) dpm[n+1][j] = 1e18;
for(int i=n; i>=1; i--){
for(int j=1; j<=n; j++){
dpm[i][j] = dpm[i+1][j];
dpm[i][j] = min(dpm[i][j], dpm[i+1][j-1] + a[i].first);
}
}
ld res = 1e18;
for(int t=0; t<=k; t++){
for(int j=1; j<=t; j++) dp[0][j] = 1e18;
for(int i=1; i<=n; i++){
for(int j=0; j<=t; j++){
dp[i][j] = dp[i-1][j] + 1.0*a[i].first/(t + 1);
if(a[i].second != 1005 && j) dp[i][j] = min(dp[i][j], dp[i-1][j-1] + 1.0*a[i].second/j);
}
}
for(int i=1; i<=n; i++){
if(i >= t && k >= i) res = min(res, dp[i][t] + 1.0*dpm[i+1][k-i]/(t + 1));
}
}
cout << res << "\n";
return 0;
}
# | 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... |