Submission #1023167

#TimeUsernameProblemLanguageResultExecution timeMemory
1023167snpmrnhlolLet's Win the Election (JOI22_ho_t3)C++17
10 / 100
1 ms436 KiB
#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 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...