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 double long double
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(),x.end()
#define de(x) cout << #x << ' ' << x << '\n';
template<class T> void prt(T l,T r){
while(l!=r) cout << *l << ' ',l++;
cout << '\n';
}
const int N=1e6+5,M=1e9+7,INF=1e18;
signed main(){
IO
int n,k;cin >> n >> k;
vector<double> a(n),b(n);
for(int i=0;i<n;i++) cin >> a[i] >> b[i];
int cnt=n;
for(int i=0;i<n;i++) if(b[i]==-1) b[i]=INF,cnt--;
double ans=INF;
for(double c=0;c<=min(cnt,k);c++){
vector<int> is(n,0);
vector<pair<pii,int> > v(n);
for(int i=0;i<n;i++){
v[i]=mp(mp(a[i],b[i]),i);
}
sort(all(v),[](pair<pii,int> aa,pair<pii,int> bb){
if(aa.ff.ss==bb.ff.ss) return aa.ff.ff>bb.ff.ff;
else return aa.ff.ss<bb.ff.ss;
});
double sum=0;
double cc=0;
for(double j=0;j<c;j++){
sum+=v[j].ff.ss/(j+1);
is[v[j].ss]=1;
cc++;
}
sort(all(v),[](pair<pii,int> aa,pair<pii,int> bb){
return aa.ff.ff<bb.ff.ff;
});
for(int i=0;i<n;i++){
if(is[v[i].ss]) continue;
cc++;
sum+=v[i].ff.ff/(c+1);
if(cc==k) break;
}
ans=min(ans,sum);
}
cout << setprecision(12) << fixed;
cout << ans << '\n';
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... |