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 = 100100;
long long x[N];
long long value(int pos) {
if (!x[pos]) x[pos] = skim(pos);
return x[pos];
}
void solve(int N, int K, long long A, int S) {
int l = -1, r = N + 1;
while (r - l > 1) {
int m = (l + r) / 2;
if (value(m) > A) r = m;
else l = m;
}
auto f = [&](long long v) {return (A <= v && v <= 2 * A); };
long long pre[K + 1] = {};
long long suf[K + 1] = {};
for (int i = 1; i <= K; i++)
pre[i] = value(i) + pre[i - 1];
if (r <= N && f(value(r) + pre[K - 1])) {
vector<int> res;
for (int i = 1; i < K; i++) res.push_back(i);
res.push_back(r);
answer(res);
return;
}
if (r < K + 1) {
impossible();
return;
}
for (int i = 1; i <= K; i++)
suf[i] = value(r - i) + suf[i - 1];
for (int i = 0; i <= K; i++) {
if (f(pre[i] + suf[K - i])) {
vector<int> res;
for (int j = 1; j <= i; j++)
res.push_back(j);
for (int j = 1; j <= K - i; j++)
res.push_back(r - j);
answer(res);
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... |