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;
typedef long long ll;
typedef long double ld;
const ll N = 2e5;
const ll inf = 1e18;
struct state{
ll a,b;
}v[N];
int p[N],p2[N];
multiset <ll> pos;
int main(){
cout<<fixed<<setprecision(69);
int n,k;
cin>>n>>k;
for(int i = 0;i < n;i++){
cin>>v[i].a>>v[i].b;
if(v[i].b == -1)v[i].b = inf;
p[i] = i;
p2[i] = i;
}
sort(p,p + n,[&](int a, int b){
return v[a].a < v[b].a;
});
sort(p2,p2 + n,[&](int a, int b){
return v[a].b < v[b].b;
});
ld costb = 0;
ll costa = 0;
for(int i = 0;i < k;i++){
pos.insert(v[p[i]].a);
costa+=v[p[i]].a;
}
ld ans = costa;
for(int i = 0;i < k;i++){
///add it
costb+=(ld)v[p2[i]].b/(i + 1);
if(pos.find(v[p2[i]].a) != pos.end()){
costa-=v[p2[i]].a;
pos.erase(pos.find(v[p2[i]].a));
}else{
costa-=*pos.rbegin();
pos.erase(prev(pos.end()));
}
ans = min(ans,(ld)costb + (ld)costa/(i + 2));
}
cout<<ans;
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... |