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 i64 = long long;
void solve(int n, int k, i64 A, int s) {
std::vector<i64> a(n, -1);
auto ask = [&](int i) -> i64 {
if (~a[i]) {
return a[i];
} else {
return a[i] = skim(i + 1);
}
};
int l = -1, r = n;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (ask(mid) * k > A && ask(mid) * k < 2 * A) {
l = mid;
break;
} else if (ask(mid) * k <= A) {
l = mid;
} else {
r = mid;
}
}
int t = std::max(0, l - k + 1);
r = std::min(n - 1, l + k - 1);
std::vector<int> ans;
i64 sum = 0;
for (; t + k - 1 <= r; t++) {
ans.clear();
sum = 0;
for (int i = 0; i < k; i++) {
sum += ask(i + t);
ans.push_back(i + t + 1);
}
if (sum >= A && sum <= 2 * A) {
answer(ans);
}
if (sum > 2 * A) {
i64 sum = ask(t + k - 1);
ans.clear();
for (int i = 0; i < k - 1; i++) {
sum += ask(i);
ans.push_back(i + 1);
}
ans.push_back(t + k);
if (sum >= A && sum <= 2 * A) {
answer(ans);
}
}
}
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... |