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;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second
#define ld double
const ll inf = 1e12;
const ll mxn = 510;
pll arr[mxn];
ll N,K;
ld dp[mxn][mxn][mxn];
multiset<ll> st;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>K;
for(int i = 1;i<=N;i++)cin>>arr[i].sc>>arr[i].fs,arr[i].fs = (arr[i].fs == -1?inf:arr[i].fs);
sort(arr+1,arr+N+1);
for(auto &i:dp)for(auto &j:i)for(auto &k:j)k = inf;
for(int i = 0;i<=N;i++)dp[0][i][0] = 0;
for(int i = 1;i<=N;i++){
//for(int j = 0;j<=N;j++){
for(int j = 0;j<=N;j++){
for(int k = 0;k<=j;k++){
auto tmp = dp[i-1][j][k];
dp[i][j][k] = min(dp[i][j][k],tmp+arr[i].sc/ld(j));
dp[i][j][k+1] = min(dp[i][j][k+1],tmp+(arr[i].fs)/ld(k+1));
}
}
}
/*
for(int i = 0;i<=N;i++){
for(int j = 0;j<=i;j++)cout<<i<<' '<<j<<":"<<dp[i][j][j]<<endl;
}cout<<endl;
*/
ld ans = inf;
for(int i = N;i>K;i--){
st.insert(arr[i].sc);
}
for(int i = K;i>=0;i--){
ll sum = 0,C = K-i;
for(auto it = st.begin();C&&it != st.end();it++,C--){
sum += *it;
}
for(int j = 0;j<=i;j++){
ld tans = sum/ld(j+1)+dp[i][j][j];
ans = min(ans,tans);
}
st.insert(arr[i].sc);
}
cout<<fixed<<setprecision(20)<<ans<<'\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... |