Submission #734544

#TimeUsernameProblemLanguageResultExecution timeMemory
7345441075508020060209tcLet's Win the Election (JOI22_ho_t3)C++14
10 / 100
25 ms336 KiB
#include<bits/stdc++.h> using namespace std; 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)

Main.cpp: In function 'double solve(int)':
Main.cpp:44:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 | for(int i=0;i<anv.size();i++){
      |             ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...