#include <bits/stdc++.h>
#include "books.h"
using namespace std;
using ll = long long;
//
// --- 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.
//
ll tri(ll a)
{
    return a * (a + 1) / 2;
}
void ans(set<int>a)
{
    vector<int> v(a.begin(),a.end());
    for (int &i : v) i++;
    answer(v);
}
void solve(int n, int k, long long a, int s) {
    vector<ll> v(n);
    for (int i = 0; i < n; i++)
    {
        v[i] = skim(i+1);
    }
    int l = 0, u = n - 1;
    ll c;
    while (l < u)
    {
        int mid = (l + u + 1) / 2;
        c = v[mid] * k - tri(k - 1);
        if (c < a) l  = mid;
        else u = mid - 1;
    }
    ll total = 0;
    if (l < k - 1) l = k - 1;
    set<int> current;
    for (int i = 0; i < k; i++)
    {
        total += v[l - i];
        current.insert(l - i);
    }
    if (a <= total && 2 * a >= total)
    {
        ans(current);
        return;
    }
    if (total >= 2 * a)
    {
        impossible();
        return ;
    }
    while (true)
    {
        l++; 
        if (l == n) impossible();
        ll nex = v[l];
        
        bool done = false;
        for (ll i : current)
        {
            if (total + nex - v[i] > 2 * a) continue;
            current.erase(v[i]);
            current.insert(l);
            total += nex - i;
            done = true;
            if (total >= a) ans(current);
            break;
        } 
        if (!done) impossible(); 
    }
    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... |