# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
969137 | Onur_Ilgaz | 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"
#include <bits/stdc++.h>
#define int long long
#define inf ((int)1e18)
using namespace std;
void solve(int N, int K, long long A, int S) {
vector <int> res(N + 1);
int l = 0, r = N + 1;
while(r - l > 1) {
int m = (l + r) / 2;
if((res[m] = skim(m)) >= A) {
r = m;
}
else {
l = m;
}
}
int ind = r;
// first way
int sum = 0;
for(int i = 1; i <= K; i++) {
if(!res[i]) res[i] = skim(i);
sum += res[i];
if(i == K - 1 and ind <= N and res[ind] + sum <= 2 * A) {
vector <int> ans;
for(int i = 1; i < K; i++) {
ans.push_back(i);
}
ans.push_back(ind);
answer(ans);
return;
}
}
for(int i = ind - K; i < ind; i++) {
if(!res[i]) res[i] = skim(i);
}
for(int i = 1; i <= K; i++) {
if(sum >= A) { // print
vector <int> ans;
for(int j = i; j <= K; j++) ans.push_back(j);
for(int j = 1; j < i; j++) ans.push_back(ind - j);
answer(ans);
return;
}
sum -= res[i];
sum += res[ind - i];
}
}