Submission #729301

#TimeUsernameProblemLanguageResultExecution timeMemory
729301tch1cherinLet's Win the Election (JOI22_ho_t3)C++17
10 / 100
2515 ms212 KiB
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; vector<int> a(n), b(n); bool good = true; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; good &= b[i] == -1 || b[i] == a[i]; } if (!good) { vector<int> order_a(n), order_b(n); iota(order_a.begin(), order_a.end(), 0); iota(order_b.begin(), order_b.end(), 0); sort(order_a.begin(), order_a.end(), [&](int i, int j) { return a[i] < a[j]; }); long double ans = 1e18; for (int mask = 0; mask < (1 << n); mask++) { for (int max_c = 0; max_c <= n; max_c++) { int c = 1, cnt = 0; long double res = 0; vector<bool> used(n, false); for (int i = 0; i < n; i++) { if (((mask >> i) & 1) && b[i] != -1 && c <= max_c) { res += (long double)b[i] / c; c++; cnt++; used[i] = true; } } for (int i : order_a) { if (cnt < k && !used[i]) { res += (long double)a[i] / c; cnt++; } } if (cnt >= k) { ans = min(ans, res); } } } cout << ans << "\n"; } else { vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int i, int j) { return a[i] < a[j]; }); long double ans = 1e18; for (int max_c = 0; max_c <= n; max_c++) { int c = 1, cnt = 0; long double res = 0; for (int i : order) { if (a[i] == b[i] && c <= max_c) { res += (long double)a[i] / c; c++; cnt++; } } for (int i : order) { if (a[i] != b[i] && cnt < k) { res += (long double)a[i] / c; cnt++; } } if (cnt >= k) { ans = min(ans, res); } } 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...