Submission #527066

#TimeUsernameProblemLanguageResultExecution timeMemory
527066couplefireLet's Win the Election (JOI22_ho_t3)C++17
100 / 100
15 ms2404 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 a[N]; double dp[N][N]; double s(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+a[i].s)/(.0+i-j)), (j>=1?dp[i-1][j-1]+(.0+a[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(){ cin.tie(0)->sync_with_stdio(0); cout << setprecision(12) << fixed; cin >> n >> k; for(int i = 1; i<=n; ++i) cin >> a[i].f >> a[i].s; int mx = 0; for(int i = 1; i<=n; ++i) if(a[i].s==-1) a[i].s = INF; else ++mx; sort(a+1, a+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(s(mid)<=s(mid+1)) hi = mid; else lo = mid+1; } cout << s(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...