# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
721169 | FatihSolak | A Difficult(y) Choice (BOI21_books) | C++17 | 2 ms | 296 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;
int cnt = 0;
long long get(int pos){
assert(cnt++ <= 40);
return skim(pos);
}
void solve(int n, int k, long long a, int s){
int l = 1,r = n+1;
while(l < r){
int m = (l+r)/2;
if(get(m) < a){
l = m + 1;
}
else r = m;
}
vector<pair<int,long long>> x;
vector<pair<int,long long>> y;
for(int i = 1;i<=k;i++){
x.push_back({i,get(i)});
}
if(l < k){
impossible();
}
if(l != n+1){
long long sum = get(l);
for(int i = 0;i<k-1;i++){
sum += x[i].second;
}
if(a <= sum && sum <= 2*a){
vector<int> ret;
for(int i = 1;i<=k-1;i++){
ret.push_back(i);
}
ret.push_back(l);
assert(ret.size() == k);
answer(ret);
}
}
if(l == k){
impossible();
}
for(int i = k;i>=1;i--){
y.push_back({l-i,get(l-i)});
}
long long sum = 0;
for(auto u:x){
sum += u.second;
}
if(a <= sum && sum <= 2*a){
vector<int> ret;
for(int i = 1;i<=k;i++){
ret.push_back(i);
}
assert(ret.size() == k);
answer(ret);
}
if(sum > 2*a){
impossible();
}
for(int i = 1;i<=k;i++){
sum -= x[k-i].second;
sum += y[k-i].second;
if(a <= sum && sum <= 2*a){
vector<int> ret;
for(int j = 1;j<=k-i;j++){
ret.push_back(j);
}
for(int j = k-1;j>=k-i;j--){
ret.push_back(y[j].first);
}
assert(ret.size() == k);
sort(ret.begin(),ret.end());
answer(ret);
}
assert(sum < a);
}
impossible();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |