Submission #747161

#TimeUsernameProblemLanguageResultExecution timeMemory
747161tch1cherinLet's Win the Election (JOI22_ho_t3)C++17
10 / 100
794 ms4624 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> A(n), B(n); for (int i = 0; i < n; i++) { cin >> A[i] >> B[i]; B[i] = (B[i] == -1 ? 1000000 : 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] ? A[i] > A[j] : B[i] < B[j]); }); long double ans = 1e9; for (int m = 0; m <= k; m++) { vector dp(n + 1, vector<long double>(m + 1, 1e9)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= i && j <= m; j++) { if (j + 1 <= m) { dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + (long double)B[order[i]] / (j + 1)); } dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (long double)A[order[i]] / (m + 1)); } } for (int p = m; p <= n; p++) { vector<int> C; for (int i = p; i < n; i++) { C.push_back(A[order[i]]); } sort(C.begin(), C.end()); if ((int)C.size() < k - m) { break; } long double res = dp[p][m]; for (int i = 0; i < k - m; i++) { res += (long double)C[i] / (m + 1); } ans = min(ans, res); } } cout << fixed << setprecision(9) << ans << "\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...