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>
#include "books.h"
using ll = long long;
template <class T> using Vec = std::vector<T>;
void solve(int N, int K, ll A, int S) {
int ok = N + 1, ng = 0;
while (ok - ng > 1) {
const int md = (ok + ng) / 2;
(skim(md) >= A ? ok : ng) = md;
}
Vec<std::pair<ll, int>> cand;
for (int i = 1; i <= std::min(K, ok - 1); ++i) {
cand.emplace_back(skim(i), i);
}
for (int i = std::max(K + 1, ok - K); i <= ok - 1; ++i) {
cand.emplace_back(skim(i), i);
}
if (ok <= N and (int) cand.size() >= K - 1) {
const auto val = skim(ok);
ll sum = 0;
for (int i = 0; i < K - 1; ++i) {
sum += cand[i].first;
}
if (sum + val <= 2 * A) {
Vec<int> ans;
for (int i = 0; i < K - 1; ++i) {
ans.push_back(cand[i].second);
}
ans.push_back(ok);
answer(ans);
return;
}
}
for (int set = 0; set < (1 << cand.size()); ++set) {
if (__builtin_popcount(set) != K) {
continue;
}
ll sum = 0;
for (int i = 0; i < (int) cand.size(); ++i) {
if (set >> i & 1) {
sum += cand[i].first;
}
}
if (A <= sum and sum <= 2 * A) {
Vec<int> ans;
for (int i = 0; i < (int) cand.size(); ++i) {
if (set >> i & 1) {
ans.push_back(cand[i].second);
}
}
answer(ans);
return;
}
}
impossible();
}
# | 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... |