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;
using ll = long long;
map<int,ll> cache;
ll query(int pos){
if (cache.count(pos)) return cache[pos];
cache[pos] = skim(pos);
return cache[pos];
}
void solve(int N, int K, long long A, int S) {
ll sum = 0;
deque<int> ans;
for (int i=1; i<=K; ++i){
sum += query(i);
ans.emplace_back(i);
}
if (A <= sum and sum <= 2*A){
answer({ans.begin(),ans.end()});
return;
}
if (sum > 2*A){
impossible();
return;
}
int res = K+1;
for (int i=(1<<16); i>0; i /= 2){
if (i+res < N and query(i+res) < A) res += i;
}
for (int i=res+1; i>=res-9; --i){
if (i > N) continue;
ll val = query(i)+sum-query(ans.back());
if (i <= K){
impossible();
return;
}
if (val <= 2*A){
sum = val;
ans.emplace_front(i);
ans.pop_back();
}
if (A <= val and val <= 2*A){
answer({ans.begin(),ans.end()});
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... |