Submission #527065

#TimeUsernameProblemLanguageResultExecution timeMemory
527065couplefireLet's Win the Election (JOI22_ho_t3)C++17
100 / 100
14 ms2308 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define f first #define s second const int N = 505; const int INF = 0x3f3f3f3f; int n, k; pii stuff[N]; double dp[N][N]; double solve(int mid){ for(int i = 1; i<=n; ++i) for(int j = 0; j<=i; ++j) dp[i][j] = min(dp[i-1][j]+(i-1-j>=mid?0:(.0+stuff[i].s)/(.0+i-j)), (j>=1?dp[i-1][j-1]+(.0+stuff[i].f)/(.0+mid+1):INF)); double ans = INF; for(int i = k-mid; i<=n; ++i) if(n-i>=mid) ans = min(ans, dp[n][i]); return ans; } int main(){ // freopen("a.in", "r", stdin); cin.tie(0)->sync_with_stdio(0); cout << setprecision(12) << fixed; cin >> n >> k; for(int i = 1; i<=n; ++i) cin >> stuff[i].f >> stuff[i].s; int mx = 0; for(int i = 1; i<=n; ++i) if(stuff[i].s==-1) stuff[i].s = INF; else ++mx; sort(stuff+1, stuff+1+n, [&](pii a, pii b){return a.s<b.s;}); int lo = 0, hi = min(k, mx); while(lo<hi){ int mid = (lo+hi)>>1; if(solve(mid)<=solve(mid+1)) hi = mid; else lo = mid+1; } cout << solve(lo) << '\n'; }
#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...