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 nx=505;
double n, k, a[nx], b[nx], cnt, c[nx];
double tmp, ans=DBL_MAX;
vector<pair<double, int>> v;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k;
for (int i=1; i<=n; i++) cin>>a[i]>>b[i], cnt+=(b[i]!=-1), v.push_back({(b[i]==-1)?1e9:b[i], i});
sort(v.begin(), v.end());
for (int i=0; i<=min(cnt, k); i++)
{
double res=0;
vector<double> t;
for (int j=1; j<=n; j++) if (!c[j]) t.push_back(a[j]);
sort(t.begin(), t.end());
for (int j=0; j+1+i<=k; j++) res+=(((double)t[j])/(i+1));
ans=min(ans, tmp+res);
if (i!=k) tmp+=(v[i].first)/(i+1), c[v[i].second]=1;
}
printf("%.5f", ans);
}
# | 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... |