# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
933801 | berr | A Difficult(y) Choice (BOI21_books) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
long long s(int a){
if(vis[a]!=-1) return vis[a];
else return vis[a] = skim(a+1);
}
void ans(int left, int right, int extra){
vector<int> a;
for(int i=1; i<=left; i++) a.push_back(i);
for(int i=vis.size()-1; i>=vis.size()-right; i--) a.push_back(i);
if(extra!=-1)a.push_back(extra+1);
sort(a.begin(), a.end());
answer(a);
}
int get(int l, int r){
int k = l-1; long long sum=0;
for(int i=0; i<l; i++) sum+=s(i);
for(int i=vis.size()-2; i>vis.size()-r-1; i--) sum+=s(i);
for(int j=17; j>=0; j--){
int tmp = k+(1<<j);
if(tmp>=vis.size()-r-1) continue;
if(s(tmp)+sum <a) k= tmp;
}
k++;
if(k<vis.size()-1-r&&sum+s(k) <=2*a && sum+s(k) >=a){
flag = 0;
ans(l, r, k);
}
return k;
}
void solve(int N, int K, long long A, int S) {
vis.resize(N+1, -1LL);
a = A;
int v=get(K-1, 0);
if(flag){
for(int i=0; i<K; i++){
s(i);
}
for(int i=v-1; i>=v-K; i--){
s(i);
}
for(int i=0; i<=K&&flag; i++){
long long sum=0;
for(int l=0; l<i; l++) sum+=s(l);
for(int l=v-1; l>=v-(K-i); l--) sum+=s(l);
if(sum>=A&&sum<=2*A){
vector<int> a;
for(int l=0; l<i; l++) a.push_back(l+1);
for(int l=v-K+i; l<=v-1; l++) a.push_back(l+1);
flag = 0;
answer(a);
}
}
}
if(flag) impossible();
}