Submission #729309

#TimeUsernameProblemLanguageResultExecution timeMemory
729309tch1cherinLet's Win the Election (JOI22_ho_t3)C++17
56 / 100
2570 ms1992 KiB
#include <bits/stdc++.h> using namespace std; const long double INF = 1e18; void 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]; } vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int i, int j) { return b[i] < b[j]; }); vector<int> new_a(n), new_b(n); for (int i = 0; i < n; i++) { new_a[i] = a[order[i]]; new_b[i] = b[order[i]]; } a = new_a, b = new_b; long double ans = INF; for (int c = 0; c <= k; c++) { vector dp(k + 1, vector<long double>(c + 1, INF)); dp[0][0] = 0; for (int i = 0; i < n; i++) { vector new_dp(n + 1, vector<long double>(c + 1, INF)); for (int j = 0; j <= k; j++) { for (int l = 0; l <= c; l++) { if (j + 1 <= k && l + 1 <= c && b[i] != -1) { new_dp[j + 1][l + 1] = min(new_dp[j + 1][l + 1], dp[j][l] + (long double)b[i] / (l + 1)); } if (j + 1 <= k) { new_dp[j + 1][l] = min(new_dp[j + 1][l], dp[j][l] + (long double)a[i] / (c + 1)); } new_dp[j][l] = min(new_dp[j][l], dp[j][l]); } } dp = new_dp; } for (int i = k; i <= n; i++) { ans = min(ans, dp[i][c]); } } cout << ans << "\n"; } int main() { cout << fixed << setprecision(9); ios::sync_with_stdio(false); cin.tie(nullptr); solve(); }
#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...