# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
656794 | 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
ll fun(ll x){
if(kp[x] == -1){
kp[x] = skim(x);
}
return kp[x];
}
void solve(int n , int m ,ll a , int s){
ll l = 1 , r = n;
ll kp[n + 1];
memset(kp , -1 , sizeof(kp));
while(r > l){
ll md = (l+r)/2;
ll z = fun(md);
kp[md] = z;
if(z>a){
r = md;
}
else{
l=md+1;
}
}
if(m > l){
impossible();
return;
}
ll tot = 0;
for(ll i = 1;m>i;i++){
tot+=fun(i);
}
if(tot + fun(l) >= a && 2*a >= tot + fun(l)){
std::vector<int> v;
for(ll i = 1;m>i;i++){
v.pb(i);
}
v.pb(l);
answer(v);
return;
}
if(m >= l){
impossible();
return;
}
tot = 0;
for(ll i = 0;m>=i;i++){
for(ll j =1;i>=j;j++){
tot+=fun(j);
}
for(ll j = l - (m - i);l>j;j++){
tot+=fun(j);
}
if(tot >= a && 2*a >= tot){
std::vector<int> v;
for(ll j =1;i>=j;j++){
v.pb(j);
}
for(ll j = l - (m - i);l>j;j++){
v.pb(j);
}
answer(j);
return;
}
tot = 0;
}
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;
}*/