# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
723315 | Marduk | A Difficult(y) Choice (BOI21_books) | C++14 | 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.
void solve(int N, int K, long long A, int S){
vector<int> sol;
int lo = 0, hi = N+1;
while(hi-lo>1){
int mid = (lo+hi)/2;
if(skim(mid) >= A) hi = mid;
else lo = mid;
}
int x = hi;
int vx = skim(i);
long long ans = 0;
vector<int> f,l;
f.clear(); l.clear();
for(int i = 1;i<K;i++){
long long q = skim(i);
ans+=q; f.push_back(q);
q = skim(x-i);
l.push_back(q);
}
if(ans+vx >= A && ans+vx <= 2*A){
for(int i = 1;i<K;i++) sol.push_back(i);
sol.push_back(x);
return sol;
}
if(K>=x) impossible();
f.push_back(skim(K));
ans+=f[K-1];
if(ans >= A && ans <= 2*A){
for(int i = 1;i<=K;i++) sol.push_back(i);
return sol;
}
for(int i = 0;i<K;i++){
if(f[i] == l[i]) impossible();
ans-=f[i]; ans+=l[i];
if(ans >= A && ans <= 2*A){
for(int j = 1+i+1;j<=K;j++) sol.push_back(j);
for(int j = x-1;j>=x-1-i;j--) sol.push_back(j);
return sol;
}
}
impossible();
}