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 <map>
#include "books.h"
using namespace std;
map<int, long long> m;
int s;
long long ask(int x) {
if (s) {
s--;
return skim(x);
} else return (long long)4e18;
}
long long get(int x, int K) {
long long ret = 0;
for (int i = 0; i < K; i++) {
if (m.find(x + i + 1) == m.end()) m[x + i + 1] = ask(x + i + 1);
ret += m[x + i + 1];
if (ret > (long long)4e18) ret = (long long)4e18;
}
return ret;
}
void solve(int N, int K, long long A, int S) {
s = S;
int l = 0, r = N - K;
while (l < r) {
int m = (l + r) / 2;
long long t = get(m, 1);
if (t < A / K) l = m + 1;
else r = m;
}
for (int e = l; e > l - K; e--) {
long long t = get(e, K);
if (t >= A && t <= 2 * A) {
vector<int> v;
for (int i = 0; i < K; i++) v.push_back(e + i + 1);
answer(v);
return;
} else if (t < A) break;
}
if (get(0, K) > 2 * A) {
impossible();
return;
} else if (get(0, K) >= A) {
vector<int> v;
for (int i = 0; i < K; i++) v.push_back(i + 1);
answer(v);
return;
}
l = K + 1, r = N - 1;
while (l <= r) {
int m = (l + r) / 2;
long long t = get(0, K - 1) + get(m, 1);
if (t < A) l = m + 1;
else if (t > 2 * A) r = m - 1;
else {
vector<int> v;
for (int i = 0; i < K - 1; i++) v.push_back(i + 1);
v.push_back(m + 1);
answer(v);
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... |