Submission #587147

#TimeUsernameProblemLanguageResultExecution timeMemory
587147rgnerdplayerLet's Win the Election (JOI22_ho_t3)C++17
0 / 100
190 ms1380 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif auto solve = [&]() { int n, k; cin >> n >> k; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (b[i] == -1) { b[i] = 1e6; } } vector<int> ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](auto i, auto j) { return b[i] < b[j]; }); vector g(n + 1, vector<int>(k + 1, 1e9)); g[n][0] = 0; for (int i = n - 1; i >= 0; i--) { g[i] = g[i + 1]; for (int j = 0; j < k; j++) { g[i][j + 1] = min(g[i][j + 1], g[i + 1][j] + a[i]); } } double ans = g[0][k]; for (int x = 0; x <= k; x++) { vector<double> f(x + 1, 1e9); f[0] = 0; for (int i = 0; i < k; i++) { int p = ord[i]; vector<double> nf(x + 1, 1e9); for (int j = 0; j <= x; j++) { nf[j] = min(nf[j], f[j] + 1.0 * a[p] / (x + 1)); if (j < x) { nf[j + 1] = min(nf[j + 1], f[j] + 1.0 * b[p] / (j + 1)); } } f = nf; ans = min(ans, f[x] + 1.0 * g[i + 1][k - i - 1] / (x + 1)); } } cout << fixed << setprecision(9) << ans << '\n'; }; solve(); 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...