#include <bits/stdc++.h>
#include "books.h"
#define pb push_back
using namespace std;
const int maxn = 1e5 + 10;
//
// --- Sample implementation for the task books ---
//
// To compile this program with the sample grader, place:
// books.h books_sample.cpp sample_grader.cpp
// in a single folder and run:
// g++ books_sample.cpp sample_grader.cpp
// in this folder.
//
int n, k, s;
long long a;
long long x[maxn];
long long do_skim(int pos)
{
if(!x[pos])x[pos] = skim(pos);
return x[pos];
}
long long check(int from, int to)
{
long long sum = 0;
for (int i = from; i <= to; ++ i)
{
sum += do_skim(i);
if(sum > 2*a)return sum;
}
return sum;
}
void solve(int N, int K, long long A, int S)
{
n = N;
k = K;
a = A;
int l = 1, r = n-k+2, mid, ans = -1; /// nai golqmoto posledovateno k-1 sys suma < a
while(l <= r)
{
mid = (l + r)/2;
long long feedback = check(mid, mid+k-2);
if(feedback <= a)
{
l = mid + 1;
ans = mid;
}
else if(feedback > a)
{
r = mid - 1;
}
}
if(ans == -1)
{
vector < int > v;
long long sum = 0;
for (int i = 1; i <= k; ++ i)
{
sum += do_skim(i);
v.pb(i);
}
if(sum >= a && sum <= 2*a)answer(v);
else impossible();
return;
}
long long sum = check(ans, ans+k-2);
vector < int > v;
for (int i = ans; i <= ans +k-2; ++ i)
v.pb(i);
int lt = ans+k-1, rt = n, res;
while(lt <= rt)
{
mid = (lt + rt)/2;
long long feedback = do_skim(mid);
if(feedback + sum > 2*a)
rt = mid - 1;
else
{
if(feedback + sum >= a && feedback + sum <= 2*a)
{
v.pb(mid);
answer(v);
return;
}
lt = mid + 1;
}
}
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... |