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;
#define fi first
#define se second
const int inf=1e9;
int main()
{
int n,k;cin>>n>>k;
pair<int,int>a[n+1];
multiset<pair<int,int> >st1,st2;
for(int i=1;i<=n;i++)
{
cin>>a[i].se>>a[i].fi;
if(a[i].fi!=-1)st1.insert(a[i]);
st2.insert({a[i].se,a[i].fi});
}
sort(a+1,a+n+1);
long double res=inf;
for(int j=0;j<=k;j++)
{
int K=k,J=j;
long double sum=0,c=1;
multiset<pair<int,int> >ST1,ST2;
ST1=st1;
ST2=st2;
while(!ST1.empty() && J>0)
{
pair<int,int>x=*ST1.begin();
if(x.fi!=-1)
{
sum+=(long double)x.fi/c;
c++;
J--;
K--;
ST2.erase(ST2.find({x.se,x.fi}));
}
ST1.erase(ST1.find(x));
}
while(!ST2.empty() && K>0)
{
pair<int,int>x=*ST2.begin();
sum+=(long double)x.fi/c;
if(x.fi==x.se) c++;
K--;
ST2.erase(ST2.find(x));
}
if(res>sum)
{
res=sum;
}
}
cout<<setprecision(9)<<fixed;
cout<<res;
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... |