Submission #1030801

#TimeUsernameProblemLanguageResultExecution timeMemory
1030801OtalpLet's Win the Election (JOI22_ho_t3)C++14
100 / 100
235 ms600 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define int ll #define pii pair<int, int> #define ff first #define ss second #define ld long double #define pb push_back pii a[200100]; bool cmp(pii a, pii b){ return a.ss < b.ss; } void solve(){ int n, k; cin>>n>>k; int dmx = 0; for(int i=1; i<=n; i++){ cin>>a[i].ff>>a[i].ss; if(a[i].ss == -1){ a[i].ss = 1e9; } } sort(a + 1, a + 1 + n, cmp); //for(int i=1; i<=n; i++) cout<<a[i].ff<<' '<<a[i].ss<<'\n'; ld ans = 1e18; for(ld D=1; D<=k+1; D++){ vector<int> d; ld res = 0; int m = k - D+1; int ok = 1; for(int i=1; i<=D-1; i++){ d.pb(i); res += 1.0 * a[i].ss / i; } multiset<pii> dd, wl; for(int i=D; i<=n; i++){ dd.insert({a[i].ff, i}); if(dd.size() > m){ wl.insert(*--(dd.end())); dd.erase(--(dd.end())); } } for(pii x: dd){ res += x.ff / D; } //cout<<"________________\n"; //cout<<D<<'\n'; ans = min(ans, res); for(int i=D; i<=n; i++){ pair<ld, int> mn{1e18, -1}; res += a[i].ss / D; d.pb(i); int mx; if(dd.find({a[i].ff, i}) != dd.end()){ dd.erase(dd.find({a[i].ff, i})); res -= a[i].ff / D; if(wl.size() == 0){ mx = 0; } else{ dd.insert(*wl.begin()); res += (*wl.begin()).ff / D; wl.erase(wl.begin()); mx = (*dd.rbegin()).ff; } } else{ mx = (dd.size() ?(*dd.rbegin()).ff :0); } ld g = 0; for(int i=d.size() - 1; i>=0; i--){ int j = d[i]; if(mx == 0){ mn = min(mn, {-a[j].ss * 1.0 / (i + 1) + g + a[j].ff / D, j}); } else{ if(a[j].ff < mx){ mn = min(mn, {-a[j].ss * 1.0 / (i + 1) + g - mx / D + a[j].ff / D, j}); } else{ mn = min(mn, {-a[j].ss * 1.0 / (i + 1) + g, j}); } } if(i > 0) g += -a[j].ss * 1.0 / (i + 1) + a[j].ss * 1.0 / i; } res += mn.ff; dd.insert({a[mn.ss].ff, mn.ss}); if(dd.size() > m){ wl.insert(*--(dd.end())); dd.erase(--(dd.end())); } ans = min(ans, res); vector<int> dq; for(int x: d){ if(x != mn.ss) dq.pb(x); } d =dq; //cout<<res<<'\n'; //for(pii x: dd) cout<<x.ff<<' '<<x.ss<<'\n'; } } cout<<fixed<<setprecision(6)<<ans<<'\n'; } signed main(){ solve(); }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:45:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   45 |             if(dd.size() > m){
      |                ~~~~~~~~~~^~~
Main.cpp:95:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   95 |             if(dd.size() > m){
      |                ~~~~~~~~~~^~~
Main.cpp:37:13: warning: unused variable 'ok' [-Wunused-variable]
   37 |         int ok = 1;
      |             ^~
Main.cpp:23:9: warning: unused variable 'dmx' [-Wunused-variable]
   23 |     int dmx = 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...