| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1366173 | taly | A Difficult(y) Choice (BOI21_books) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#define lli long long
#include "books.h"
using namespace std;
//
// --- 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.
//
vector<int> sei;
int bs(int l, int r, lli a){
if(l>r)return -1;
int m=(l+r)/2;
lli s = skim(m);
sei[m]=s;
if(s>=a){
int op=bs(l, m-1, a);
if(op==-1)return m;
else return op;
}else return bs(m+1, r, a);
}
void solve(int n, int K, long long A, int S) {
// TODO implement this function
int maior = bs(0, n-1, A);
if(maior==-1)maior=n;
sei.assign(n, -1);
lli com=0, fim=0;
for(int i=0; i<K; i++){
lli x=skim(i);
sei[i]=x;
com+=x;
}
for(int i=0; i<K; i++){
lli x=skim(maior-1-i);
sei[n-1-i]=x;
fim+=x;
}
if(com>2*A){
impossible();
return;
}
// if(fim<A){
// impossible();
// return;
// }
if(maior!=n&&sei[maior]+com-sei[K-1]<=2*A){
vector<int> resp;
for(int i=0; i<K-1; i++){
resp.pb(i+1);
}
resp.pb(maior);
answer(resp);
return 0;
}else {
// if(maior==n||sei[maior]+com-sei[K-2]>=2*A){
int p=k-1;
int f=maior-1;
while(com<A){
com-=sei[p];
p--;
com+=sei[f];
f--;
}
vector<int> resp;
for(int i=0; i<=p; i++){
resp.pb(i+1);
}
for(int i=maior-1; i>f; i--){
resp.pb(i+1);
}
answer(resp);
return 0;
}
// if (skim(2) == 42) {
// impossible();
// } else {
// answer({1, 3});
// }
}
