# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
734545 | 1075508020060209tc | Let's Win the Election (JOI22_ho_t3) | C++14 | 28 ms | 340 KiB |
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 double long double
int n;int K;
int M;
int ar[200005];
int br[200005];
double ans;
bool cmp(pair<int,int>i,pair<int,int>j){
if(i.second<j.second){return 1;}
if(i.second>j.second){return 0;}
if(i.first<j.first){return 1;}
return 0;
}
double solve(int m){
vector<pair<int,int>>tar;
for(int i=1;i<=n;i++){
tar.push_back({ar[i],br[i]});
}
sort(tar.begin(),tar.end(),cmp);
vector<pair<int,int>>anv;
for(int i=0;i<m;i++){
anv.push_back(tar[i]);
}
vector<int>tv;
for(int i=m;i<n;i++){
tv.push_back(tar[i].first);
}
sort(tv.begin(),tv.end());
/*
for(int i=0;i<tar.size();i++){
cout<<tar[i].first<<"_"<<tar[i].second<<endl;
}*/
double ret=0;
for(int i=0;i<K-m;i++){
ret+=(double)tv[i]/(double)(m+1);
}
for(int i=0;i<anv.size();i++){
ret+=(double)anv[i].second/(double)(i+1);
}
//cout<<fixed<<setprecision(6)<<ret<<endl;
return ret;
}
signed main(){
cin>>n>>K;
M=0;
for(int i=1;i<=n;i++){
cin>>ar[i]>>br[i];
if(br[i]!=-1){
M++;
}else{
br[i]=2000;
}
}
ans=500000;
for(int i=0;i<=min(K,M);i++){
ans=min(ans,solve(i));
// cout<<endl<<endl;
}
cout<<fixed<<setprecision(6)<<ans<<endl;
/*
double l=0;double r=500000;
for(int ttt=0;ttt<90;ttt++){
double mi=(l+r)/2;
if(ok(mi)){
l=mi;
}else{
r=mi;
}
}
cout<<fixed<<setprecision(6)<<l<<endl;
*/
}
Compilation message (stderr)
# | 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... |