# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
886982 | dubabuba | Let's Win the Election (JOI22_ho_t3) | C++14 | 2567 ms | 760 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 10;
const int mxn = 20;
int a[mxn], n;
int b[mxn], k;
vector<int> good;
vector<int> badd;
double ans = 1e9;
void solve(int map) {
vector<int> vote = badd;
vector<int> help;
double ret = 0.0;
for(int i = 0; i < good.size(); i++)
if(map & (1 << i))
help.push_back(good[i]);
else
vote.push_back(good[i]);
if(help.size() > k) return;
sort(help.begin(), help.end(), [&](int i, int j) { return b[i] < b[j]; });
sort(vote.begin(), vote.end(), [&](int i, int j) { return a[i] < a[j]; });
int helpers = 0;
for(int i : help) {
ret += 1.0 * b[i] / (1.0 + helpers);
helpers++;
}
for(int j = 0; j < (k - help.size()); j++) {
int i = vote[j];
ret += 1.0 * a[i] / (1.0 + helpers);
}
ans = min(ans, ret);
}
int main() {
cin >> n >> k;
for(int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if(b[i] == -1) {
b[i] = inf;
badd.push_back(i);
}
else
good.push_back(i);
}
for(int bit = 0; bit < (1 << good.size()); bit++)
solve(bit);
cout << setprecision(5) << fixed << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |