# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
528873 | OttoTheDino | 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"
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.
//
#define rep(i,s,e) for (ll i = s; i <= e; ++i)
#define all(a) a.begin(), a.end()
typedef long long ll;
const ll mx = 2e5;
ll x[mx];
void solve(ll n, ll k, long long a, ll S) {
vector<int> ans(k);
iota(all(ans),1);
ll s = 0;
rep (i,1,k) {
x[i] = skim(i);
s += x[i];
}
if (s>2*a) impossible();
else if (s>=a) {
answer(ans);
return;
}
else {
ll lo = k+1, hi = n+1;
while (lo<hi) {
ll mid = (lo+hi)/2;
x[mid] = skim(mid);
if (x[mid]>=a) hi = mid;
else lo = mid+1;
}
if (lo!=n+1) {
if (s+x[lo]-x[k]<=2*n) {
ans[k-1] = lo;
answer(ans);
return;
}
}
rep (i,1,k) {
x[n-i+1] = skim(n-i+1);
s += x[n-i+1] - x[k-i+1];
ans[k-i] = n-i+1;
if (s>=a) {
answer(ans);
return;
}
}
}
impossible();
}