#include <iostream>
#include <algorithm>
using namespace std;
#define ld long double
main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k;
cin>>n>>k;
bool use[n]={0};
pair<ld,ld> c[n];
pair<ld,int> a[n],b[n];
for(int i=0;i<n;i++)
{
cin>>a[i].first>>b[i].first;
if(b[i].first==-1)b[i].first=1e18;
a[i].second=i;
b[i].second=i;
c[i].first=b[i].first;
c[i].second=-a[i].first;
}
sort(c,c+n);
// cout<<"order "<<endl;
for(int i=0;i<n;i++)
{
b[i].first=c[i].first;
a[i].first=-c[i].second;
// cout<<c[i].first<<' '<<c[i].second<<endl;
}
// cout<<endl;
cout.precision(4);
sort(a,a+n);
// sort(b,b+n);
ld ot=0,cst=0;
ld ans=1e18;
for(int i=0;i<=n and ot<=k;i++)
{
ld tmp=0,tot=ot;
for(int i=0;i<n and tot<k;i++)
{
if(!use[a[i].second])
{
tmp+=a[i].first;
tot++;
}
}
ans=min(ans,(tmp/(ot+1))+cst);
if(i<n)
{
ot++;
use[b[i].second]=1;
cst+=(b[i].first/ot);
}
}
cout<<fixed<<ans<<endl;
}
Compilation message (stderr)
Main.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
5 | main()
| ^~~~| # | 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... |