#include <iostream>
#include <algorithm>
#include <vector>
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+2]={0};
pair<ld,ld> c[n+2];
pair<ld,int> a[n+2],b[n+2];
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=-a[i].first+b[i].first;
c[i].second=b[i].first;
}
sort(c,c+n);
// cout<<"order "<<endl;
for(int i=0;i<n;i++)
{
b[i].first=c[i].second;
// b[i].first=c[i].first+c[i].second;
a[i].first=c[i].second-c[i].first;
// cout<<a[i].first<<' '<<b[i].first<<' '<<b[i].first-a[i].first<<endl;;
}
// cout<<endl;
cout.precision(4);
sort(a,a+n);
// sort(b,b+n);
// for(int i=0;i<n;i++)
// {
// b[i].first-=c[b[i].second].second;
// }
ld ot=0,cst=0;
ld ans=1e18;
vector<int> allp;
for(int i=0;i<=n and ot<=k;i++)
{
sort(begin(allp),end(allp));
cst=0;
for(int i=1;i<=ot;i++)
{
cst+=(allp[i-1]/(ld)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;
// cout<<"used "<<a[i].second<<endl;
tot++;
}
}
ans=min(ans,(tmp/(ot+1))+cst);
// cout<<"Taken "<<ot<<' '<<tmp<<' '<<cst<<' '<<(tmp/(ot+1))+cst<<endl;
if(i<n)
{
ot++;
use[b[i].second]=1;
allp.push_back(b[i].first);
// cst+=(b[i].first/ot);
// cout<<"Taking "<<b[i].second<<endl;
}
}
cout<<fixed<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | 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... |