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 namespace std;
const int N = 1e5 + 69;
long long was[N], sum;
void solve(int n, int k, long long a, int s) {
int l = 1, r = n, lst = n + 1;
vector<int> ans;
while (l <= r) {
int mid = (l + r) / 2;
long long b = 0;
if (was[mid] > 0)
b = was[mid];
else
b = skim(mid);
was[mid] = b;
if (b >= a) {
lst = mid;
r = mid - 1;
}
else
l = mid + 1;
}
if (lst != n + 1) {
for (int i = 1;i <= k - 1;i++) {
if (!was[i])
was[i] = skim(i);
sum += was[i];
}
sum += was[lst];
if (sum >= a && sum <= 2 * a) {
for (int i = 1;i <= k - 1;i++)
ans.push_back(i);
ans.push_back(lst);
answer(ans);
}
}
n = lst - 1;
assert(n >= k);
for (int i = 1;i <= k;i++) {
if (!was[i])
was[i] = skim(i);
sum += was[i];
}
if (sum > 2 * a)
impossible();
else if (sum >= a && sum <= 2 * a) {
for (int i = 1;i <= k;i++)
ans.push_back(i);
answer(ans);
}
sum = 0;
for (int i = n, j = 0;j < k;i--,j++) {
if (!was[i])
was[i] = skim(i);
sum += was[i];
}
if (sum < a)
impossible();
else if (sum >= a && sum <= 2 * a) {
for (int i = n,j = 0;j < k;i--,j++)
ans.push_back(i);
answer(ans);
}
assert(was[n] < a && was[n] > 0);
int ptr = n, d = 0;
while (d < k) {
sum -= was[ptr];
sum += was[n - ptr + 1];
ptr--;
d++;
if (sum >= a && sum <= 2 * a)
break;
}
for (int i = 1;i <= d;i++)
ans.push_back(i);
for (int i = n - k + 1;i <= ptr;i++)
ans.push_back(i);
assert(sum >= a && sum <= 2 * a);
answer(ans);
}
# | 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... |