Submission #1000930

#TimeUsernameProblemLanguageResultExecution timeMemory
1000930amine_arouaA Difficult(y) Choice (BOI21_books)C++17
20 / 100
142 ms1880 KiB
#include <bits/stdc++.h>
using namespace std;
#define intt long long
#define forr(i , x , y) for(int i = x ;i <= y;i++)
#define pb push_back
#define fore(i , n) for(int i = 0 ; i <n;i++)
/**
 * skims through the i-th book and returns its difficulty x_i (1 <= i <= N).
 */
long long skim(int);

/**
 * buys your selection of books. This function has to be called with
 * v = {i_1, ..., i_K} (1 <= i_1, ..., i_K <= N) where the i_j's are pairwise
 * distinct and satisfy A <= x_{i_1} + ... + x_{i_K} <= 2 A.
 */
void answer(std::vector<int>);

/**
 * states that it is impossible to buy a set of K books with the desired difficulty.
 */
void impossible();

void solve(int n, int k, long long a, int s)
{
    vector<intt> x(n + 1);
    vector<intt> pref(n + 1);
    forr(i , 1,n)
    {
        x[i] = skim(i);
        pref[i] = x[i] + pref[i - 1];
    }
    vector<int> ans;
    forr(i , 1 , n)
    {
        if(x[i] >= a)
        {
            if(k - 1 < i && pref[k - 1] + x[i] <= 2 * a)
            {
                forr(j , 1 , k - 1)
                    ans.pb(j);
                ans.pb(i);
                answer(ans);
                return;
            }
        }
    }
    forr(i , k , n)
    {
        if(x[i]>= a)
            break;
        if(a <= pref[i] - pref[i - k] && pref[i] - pref[i - k] <= 2ll * a)
        {
            forr(j , i - k + 1 , i)
            {
                ans.pb(j);
            }
            answer(ans);
            return ;
        }
    }
    impossible();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...