# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1189737 | PlayVoltz | A Difficult(y) Choice (BOI21_books) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
void solve(int n, int k, long long a, int s){
int sum=0, low=k-1, high=n+1;
vector<int> vect(n+1), ans, temp;
for (int i=1; i<=k; ++i)vect[i]=skim(i), sum+=vect[i];
if (sum>2*a){
impossible();
return;
}
sum-=vect[k];
while (low+1<high){
int mid=(low+high)/2;
vect[mid]=skim(mid);
if (sum+vect[mid]>=a)high=mid;
else low=mid;
}
if (sum+vect[high]<=2*a){
for (int i=1; i<k; ++i)ans.pb(i);
ans.pb(high);
answer(ans);
return;
}
for (int i=1; i<=k; ++i)temp.pb(i);
for (int i=max(k, high-k); i<high; ++i)vect[i]=skim(i), temp.pb(i);
for (int i=k, sum=0; i<=temp.size(); ++i){
for (int j=i-k; j<i; ++j)sum+=vect[temp[j]];
if (a<=sum&&sum<=2*a){
for (int j=i-k; j<i; ++j)ans.pb(temp[j]);
answer(ans);
return;
}
}
impossible();
}