# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782934 | Hanksburger | 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.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
vector<long long> ans;
long long x[100005];
void solve(int n, int k, long long a, int s)
{
long long l=1, r=n-k+1;
while (l<=r)
{
long long mid=(l+r)/2, sum=0;
for (long long i=mid; i<mid+k; i++)
{
if (!x[i])
x[i]=skim(i);
sum+=x[i];
}
if (a<=sum && sum<=a*2)
{
for (long long i=mid; i<mid+k; i++)
ans.push_back(i);
answer(ans);
return;
}
if (sum<a)
l=mid+1;
else
r=mid-1;
}
long long pre=0;
for (long long i=1; i<k; i++)
{
if (!x[i])
x[i]=skim(i);
pre+=x[i];
}
l=k, r=n;
while (l<=r)
{
long long mid=(l+r)/2;
if (!x[mid])
x[mid]=skim(mid);
if (a<=pre+x[mid] && pre+x[mid]<=a*2)
{
for (long long i=1; i<k; i++)
ans.push_back(i);
ans.push_back(mid);
answer(ans);
return;
}
if (pre+x[mid]<a)
l=mid+1;
else
r=mid-1;
}
impossible();
}