Submission #600083

#TimeUsernameProblemLanguageResultExecution timeMemory
600083alexander707070A Difficult(y) Choice (BOI21_books)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#include "books.h"
using namespace std;

int n,k,s;
long long a,curr,val,sum,sum2;
vector< pair<long long,int> > w;
vector<int> ans;
long long p[MAXN];

void solve(int N,int K,long long A,int S){
    n=N; k=K; a=A; s=S;

    int l=0,r=n+1,mid;
    while(l+1<r){
        mid=(l+r)/2;
        curr=skim(mid);
        if(curr>=a){
            r=mid;
        }else{
            l=mid;
        }
    }

    if(r<k)impossible();

    for(int i=1;i<=k-1;i++){
        w.push_back({skim(i),i});
        sum+=w.back().first;
    }
    for(int i=max(k,r-k+1);i<=r-1;i++){
        w.push_back({skim(i),i});
    }

    if(r!=n+1)val=skim(r);

    for(int i=0;i+k-1<w.size();i++){
        curr=0; ans.clear();
        for(int f=0;f<=i+k-1;f++){
            curr+=w[f].first;
            ans.push_back(w[f].second);
        }
        if(curr>=a and curr<=2*a){
            answer(ans);
            return;   
        }
    }

    if(r==n+1 or val+sum>2*a){
        impossible();
    }else if(val+sum<2*a){
        for(int i=1;i<=k-1;i++){
            ans.push_back(i);
        }
        ans.push_back(r);
        answer(ans);
    }else{
        for(int i=0;i+k-2<w.size();i++){
            curr=0; ans.clear();
            for(int f=0;f<=i+k-2;f++){
                curr+=w[f].first;
                ans.push_back(w[f].second);
            }
            ans.push_back(r);
            if(curr+val>=a and curr+val<=2*a){
                answer(ans);   
                return;
            }
        }
        impossible();
    }
}

Compilation message (stderr)

books.cpp:9:13: error: 'MAXN' was not declared in this scope
    9 | long long p[MAXN];
      |             ^~~~
books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=0;i+k-1<w.size();i++){
      |                 ~~~~~^~~~~~~~~
books.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(int i=0;i+k-2<w.size();i++){
      |                     ~~~~~^~~~~~~~~