# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
656769 | ktkerem | A Difficult(y) Choice (BOI21_books) | C++17 | 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"
typedef long long ll;
typedef std::pair<ll , ll> llll;
typedef std::string str;
#define debug std::cout << "debug" << std::endl
#define pb push_back
void solve(int n , int m ,ll a , ints){
ll l = 1 , r = n;
ll kp[n + 1];
memset(kp , -1 , sizeof(kp));
while(r > l){
ll md = (l+r)/2;
ll z = skim(md);
kp[md] = z;
if(z>=a){
r = md;
}
else{
l=md+1;
}
}
ll js = l;
ll p = 0;
ll t = 0;
for(ll i = 1;m > i;i++){
if(kp[i] != -1){
t+=kp[i];
continue;
}
ll o = skim(i);
kp[i] = o;
t+=o;
}
ll ss = std::max(js - m , m+1);
if(t + kp[js] >= a && 2 * a >= t + kp[js]){
std::vector<int> vec;
for(ll i = 1;m>i;i++){
vec.pb(i);
}
vec.pb(js);
answer(vec);
return;
}
if(kp[m] == -1){
kp[m] = skim(m);
}
t+= kp[m];
if(t >= a && t<=2*a){
std::vector<int> vec;
for(ll i = 1;m>=i;i++){
vec.pb(i);
}
answer(vec);
return;
}
ll o = 1;
while(o + ss <= js){
if(kp[o + ss - 1] == -1){
skim(o + ss -1);
}
t+=kp[o + ss - 1];
t-=kp[o];
if(t >= a && 2 * a >= t){
std::vector<int> vec;
for(ll i = o+1;m>=i;i++){
vec.pb(i);
}
for(ll i = 0;o>i;i++){
vec.pb(ss + i);
}
answer(vec);
return;
}
o++;
}
impossible();
}
/*int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
ll t = 1;std::cin >> t;
while(t--){
solve();
}
return 0;
}*/