// Be name khoda //
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long ll;
const int maxn5 = 3e5 + 10;
const int lg = 20;
#define pb push_back
#define se second
#define fi first
//
// --- 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;
ll A, have;
ll a[maxn5];
inline bool check(int pre){
ll have = 0;
if(a[ n - (k - 1 - pre)] == -1)
a[ n - (k - 1 - pre)] = skim( n - (k - 1 - pre));
for(int i = 1; i <= pre; i++)
have += a[i];
for(int i = n - (k - 1 - pre); i <= n; i++)
have += a[i];
return have >= A;
}
inline bool ok(int id){
return have + skim(id) <= 2 * A;
}
inline int rebuild(){
ll have = 0;
for(int i = 1; i <= k; i++){
a[i] = skim(i);
if(i < k)
have += a[i];
}
int lo = k, hi = n + 1;
while(hi - lo > 1){
int mid = (lo + hi) >> 1;
a[mid] = skim(mid);
if(have + mid <= 2 * A)
lo = mid;
else
hi = mid;
}
if(have + a[lo] >= A){
vector <int> ret;
ret.clear();
for(int i = 1; i < k; i++)
ret.pb(i);
ret.pb(lo);
answer(ret);
}
return lo;
}
void solve(int N, int K, long long AA, int S) {
n = N;
k = K;
s = S;
A = AA;
memset(a, -1, sizeof a);
n = rebuild();
for(int i = n - k + 1; i <= n; i++)
a[i] = skim(i);
int lo = 0, hi = k;
while(hi - lo > 1){
int mid = (lo + hi) >> 1;
if(check(mid)) lo = mid;
else hi = mid;
}
//cout << lo << endl;
//cout << check(1) << endl;
if(lo == 0){
have = 0;
for(int i = n - k + 1; i <= n; i++)
have += a[i];
if(have < A)
impossible();
}
if(lo == k - 1){
have = 0;
for(int i = 1; i <= k; i++)
have += a[i];
if(have > 2 * A)
impossible();
}
have = 0;
for(int i = 1; i <= lo; i++)
have += a[i];
for(int i = n - (k - 1 - lo) + 1; i <= n; i++)
have += a[i];
int l = lo + 1, r = n - (k - 1 - lo) + 1;
while(r - l > 1){
int mid = (l + r) >> 1;
if(ok(mid))
l = mid;
else
r = mid;
}
vector <int> ret;
ret.clear();
for(int i = 1; i <= lo; i++)
ret.pb(i);
ret.pb(l);
for(int i = n - (k - 1 - lo) + 1; i <= n; i++)
ret.pb(i);
answer(ret);
if (skim(2) == 42) {
impossible();
} else {
answer({1, 3});
}
}
Compilation message
foodcourt.cpp:3:10: fatal error: books.h: No such file or directory
3 | #include "books.h"
| ^~~~~~~~~
compilation terminated.