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;
const int N = 505;
double dp[N][N];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k; cin >> n >> k;
vector<array<int, 2>> a(n);
int c=0;
for(auto &[i, l]: a) cin >> i >> l, c+=(l!=-1);
sort(a.begin(), a.end(), [&](auto x, auto y){
if(x[1]==y[1]) return x[0] < y[0];
else if(y[1]==-1) return true;
else if(x[1]==-1) return false;
return x[1]<y[1];
});
map<array<double, 3>, double> mp;
mp[{0, 0, 0}]=0;
for(int i=0; i<n; i++){
vector<array<double, 4>> be;
for(auto [b, j]: mp){
// cout<<j<<"\n";
if(a[i][1]!=-1){
be.push_back({b[0]+((double)a[i][1]/(double)(b[1]+1)), b[1]+1, b[2], j});
}
be.push_back({b[0], b[1], b[2]+1.0, j+(double)a[i][0]});
}
for(auto i: be){
// cout<<i[0]<<" "<<i[1]<<" "<<i[2]<<" "<<i[3]<<"\n";
if(mp.count({i[0], i[1], i[2]})){
mp[{i[0], i[1], i[2]}]=min( mp[{i[0], i[1], i[2]}], i[3]);
}
mp[{i[0], i[1], i[2]}]=i[3];
}
}
double ans=1e9;
for(auto [b, j]: mp){
/// cout<<j<<"\n";
if(b[1]+b[2]==k){
ans=min(ans, b[0]+j/(b[1]+1));
}
}
cout<<setprecision(9)<<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... |