Submission #416783

#TimeUsernameProblemLanguageResultExecution timeMemory
416783jainbot27A Difficult(y) Choice (BOI21_books)C++17
45 / 100
2 ms1008 KiB
// Difficult(y) Choice
 
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
 
using ll=long long;
 
#define FOR(i, a, b) for(int i=a; i<b; i++) 
#define ROF(i, a, b) for(int i=b-1; i>=a; i--)
#define F0R(i, n) FOR(i, 0, n) 
#define R0F(i, n) ROF(i, 0, n) 
 
#define f first
#define s second
#define pb push_back
#define siz(x) (int)x.size() 
 
const int mxN=1e5+10;
 
int n, k, s; ll a;
ll x[mxN];
 
ll qry(int V){
    if(x[V]!=-1) return x[V]; 
    x[V]=skim(V+1);
    return x[V];
}
 
void chk(int X){
    if(X<0) return;
    if(X+k>n) return;
    ll sum=0;
    vector<int> Ans;
    FOR(i, X, X+k){
        sum+=qry(i); 
        Ans.pb(i+1);
    }
    if(sum>=a&&sum<=2*a) {
        answer(Ans); 
        exit(0);
    }
}
void solve(int N, int K, ll A, int S){
    n=N, k=K, a=A, s=S; 
    memset(x, -1, sizeof x);
    {
        ll sum=0; 
        F0R(i, k-1) sum+=qry(i);
        int lo=k-1, hi=n;
        while(lo<hi){
            int m=(lo+hi)/2; 
            // cerr << m << endl;
            if(qry(m)+sum>2*a) hi=m-1; 
            else if(qry(m)+sum<a) lo=m+1; 
            else{
                vector<int> Ans; F0R(i, k-1) Ans.pb(i+1);
                Ans.pb(m+1); 
                answer(Ans); exit(0);
            }
        }
        n=hi; 
    }
    int lo=0, hi=n; 
    while(lo+1<hi){
        int m=(lo+hi)/2; 
        if(qry(m)*k>=a) hi=m;
        else lo=m+1; 
    }
    FOR(i, lo-k+1, lo+1){
        chk(i);
    }
    impossible();
    // assert(n==s);
    // task is query 40 books and try to see if we can get a set of K books such that A<=\sum<=2A we have K is less than 10 so SMALL 
    // solve subtask by subtask:
    /*
        observation, problem has to require BINARY SEARCH
        subtask 1: we can just like iterte over first 2 books, check which if we have a third one 
        subtask 2: if the last element we take is <=A then if the previous elements are >A, we can find a solution 
 
        current solution:
        binary search for first X such that x[X]*K>=A then notice this element has to be used
        at least I think that is true 
 
        20+17 queries minus a couple 
 
        thing is we also need to check for the smallest number with value >= A 
 
        We probably have 80 points 
    */
    // vector<ll> x(n); 
    // F0R(i, n){
    //     x[i]=skim(i+1); 
    // }
    // ll sum=0; 
    // F0R(i, k-1) sum+=qry(i); 
    // FOR(i, k-1, n){
    //     sum+=qry(i); 
    //     if(sum>=a&&sum<=2*a){
    //         vector<int> ans;
    //         FOR(j, i-k+1, i+1)  ans.pb(j+1); 
    //         answer(ans); 
    //     }
    //     sum-=qry(i-k+1);
    // }
    // impossible();
}
 
// int main(){
//     cin.tie(0)->sync_with_stdio(0); 
 
// }
#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...