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 int long long
#define all(x) x.begin(),x.end()
#define double long double
int INF=1e9;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
int k;cin>>k;
vector<int> a(n),b(n);
for(int i=0;i<n;i++){
cin>>a[i];
cin>>b[i];
if(b[i]==-1){
b[i]=INF;
}
}
double ans=INF;
for(int i=0;i<=k;i++){
double cnt=0;
vector<bool> vis(n);
vector<int> c(n);
iota(all(c),0);
sort(all(c),[&](int i,int j){return b[i]<b[j];});
for(int j=0;j<i;j++){
int p=c[j];
vis[p]=1;
cnt+=b[p]/(double)(j+1);
}
sort(all(c),[&](int i,int j){return a[i]<a[j];});
int ptr=0;
for(int j=0;j<k-i;j++){
while(vis[c[ptr]]){
ptr++;
}
int p=c[ptr];
vis[p]=1;
cnt+=a[p]/(double)(i+1);
ptr++;
}
ans=min(ans,cnt);
}
cout<<fixed<<setprecision(9)<<ans<<endl;
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... |