# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
687339 | Alcabel | A Difficult(y) Choice (BOI21_books) | C++17 | 0 ms | 0 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;
void solve(int n, int k, long long a, int s) {
int l = -1, r = n;
long long found = -1;
while (r - l > 1) {
int m = l + (r - l) / 2;
long long cur = skim(m + 1);
if (cur >= a) {
found = cur;
r = m;
} else {
l = m;
}
}
vector<int> ans(k);
iota(ans.begin(), ans.end(), 1);
if (r + 1 <= k - 1) {
impossible();
return;
}
vector<long long> first(k);
long long sumFirst = 0;
for (int i = 0; i < k; ++i) {
first[i] = skim(i + 1);
sumFirst += first[i];
}
if (r != n && sumFirst - first.back() + found <= 2 * a) {
ans.back() = r + 1;
answer(ans);
return;
}
n = r;
vector<long long> last(k);
long long sumLast = 0;
for (int i = n - 1; i >= n - k; --i) {
last[n - 1 - i] = skim(i + 1);
sumLast += last[n - 1 - i];
}
if (sumFirst >= a && sumFirst <= 2 * a) {
answer(ans);
return;
}
if (sumLast >= a && sumLast <= 2 * a) {
iota(ans.begin(), ans.end(), n - k + 1);
answer(ans);
return;
}
if (sumFirst > 2 * a || sumLast < a) {
impossible();
return;
}
long long sum = sumFirst;
iota(ans.begin(), ans.end(), 1);
for (int i = k - 1; sum < a; --i) {
assert(i >= 0);
sum -= first[i];
sum += last[k - 1 - i];
ans[i] = n - (k - 1 - i);
}
answer(ans);
}