# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
944696 | thelegendary08 | A Difficult(y) Choice (BOI21_books) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long ll;
//
// --- 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.
//
void solve(int N, int K, long long A, int S) {
vector<long long int>v(N);
ll s = 0;
for(int i = 1;i<=K-1;i++){
v[i-1] = skim(i);
s += v[i-1];
}
v[N-1] = skim(N);
if(s + v[N-1] >= A && s + v[N-1] <= 2*A){
vector<int>ret;
for(int i = 1;i<=K-1;i++){
ret.push_back(i);
}
ret.push_back(N);
answer(ret);
}
if(s + v[N-1] < A){
s+= v[N-1];
//move until good then bsta
bool ok = 0;
int p = N-1;
while(p > N - k && !ok){
ll cur = skim[p];
v[p-1] = cur;
s-=v[N-p];
s+=v[p-1];
if(s >= A && s <= 2*A){
vector<int>ret;
for(int i = 1;i<=K - (N-p+1);i++){
ret.pb(i);
}
for(int i = p;i<=N;i++)ret.pb(i);
answer(ret);
}
else if(s >= A){
ok = 1;
}
}
if(p == N - k)impossible();
s -= v[p-1];
int l = K - (N-p+1) + 1;
int r = p-1;
while(l <= r){
int k = (l + r)/2;
int cur = skim(k);
if(s + cur <= 2*A && s + cur >= A){
vector<int>ret;
for(int i = 1;i<=K - (N-p+1);i++){
ret.pb(i);
}
ret.pb(k);
for(int i = p+1;i<=N;i++)ret.pb(i);
answer(ret);
}
else if(s + cur > 2*A)r = k-1;
else l = k + 1;
}
}
else{
//bsta
int l = K;
int r = N-1;
}
impossible();
}