Submission #824351

#TimeUsernameProblemLanguageResultExecution timeMemory
824351petezaLet's Win the Election (JOI22_ho_t3)C++14
0 / 100
1 ms468 KiB
#include <bits/stdc++.h> using namespace std; int n, k; long double a[1005], b[1005]; int sA[1005], sB[1005]; int sAs, sBs; bool vis[1005]; int main() { cin.tie(0) -> sync_with_stdio(0); cin >> n >> k; for(int i=0;i<n;i++) { cin >> a[i] >> b[i]; sA[sAs++] = i; if(b[i] != -1) sB[sBs++] = i; } sort(sA, sA+sAs, [&](int i, int j){ return a[i] <= a[j]; }); sort(sB, sB+sBs, [&](int i, int j){ return b[i] <= b[j]; }); long double ans, cans = 1e9; for(int bs=0;bs<=min(sBs, k);bs++) { memset(vis, 0, sizeof vis); int cnt = 0; ans = 0; for(int i=0;i<bs;i++) { cnt++; vis[sB[i]] = 1; ans += b[sB[i]]/(i+1); } for(int i=0;i<n&&cnt!=k;i++) { if(vis[sA[i]]) continue; cnt++; ans += a[sA[i]]/(bs+1); } if(cnt != k) exit(2); cans = min(cans, ans); } cout << fixed << setprecision(5) << cans; }
#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...