Submission #640758

#TimeUsernameProblemLanguageResultExecution timeMemory
640758peter940324Let's Win the Election (JOI22_ho_t3)C++17
10 / 100
32 ms404 KiB
#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<double,double> #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=0; set<int> A,B; vector<pii> v(n); for(int i=0;i<n;i++){ v[i]=mp(a[i],i); } sort(all(v)); for(int i=0;i<k;i++){ A.insert(v[i].ss); ans+=v[i].ff; } for(double c=1;c<=min(cnt,k);c++){ int mxa=0,mxai=-1; for(auto x:A){ if(a[x]>mxa){ mxa=a[x]; mxai=x; } } int mn=INF,mni=-1; for(int i=0;i<n;i++){ if(B.count(i)) continue; if(A.count(i)){ if(b[i]-a[i]<mn){ mn=b[i]-a[i]; mni=i; } }else{ if(b[i]-mxa<mn){ mn=b[i]-mxa; mni=i; } } } if(A.count(mni)){ A.erase(mni); B.insert(mni); }else{ A.erase(mxai); B.insert(mni); } double sum=0,cc=1; vector<double> bb,aa; for(auto x:B){ bb.pb(b[x]); } for(auto x:A){ aa.pb(a[x]); } sort(all(bb)); sort(all(aa)); for(int i=0;i<bb.size();i++){ sum+=bb[i]/cc; cc++; } for(int i=0;i<aa.size();i++){ sum+=aa[i]/cc; } ans=min(ans,sum); } cout << setprecision(15) << fixed; cout << ans << '\n'; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:83:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for(int i=0;i<bb.size();i++){
      |               ~^~~~~~~~~~
Main.cpp:87:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for(int i=0;i<aa.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...