# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
981574 | OAleksa | A Difficult(y) Choice (BOI21_books) | C++14 | 1 ms | 856 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;
const int N = 1e5 + 69;
long long was[N], sum = 0;
//
// --- 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.
//
void solve(int n, int k, long long a, int s) {
int l = 1, r = n, lst = -1;
vector<int> ans;
while (l <= r) {
int mid = (l + r) / 2;
long long b = 0;
if (was[mid] > 0)
b = was[mid];
else
b = skim(mid);
was[mid] = b;
if (b >= a) {
lst = mid;
r = mid - 1;
}
else
l = mid + 1;
}
if (lst == -1) {
for (int i = n, j = 0;i >= 1, j < k;j++, i--) {
if (!was[i])
was[i] = skim(i);
sum += was[i];
}
if (sum < a)
impossible();
else if (sum >= a && sum <= 2 * a) {
for (int i = n,j = 0;i >= 1,j < k;i--,j++)
ans.push_back(i);
answer(ans);
}
long long ss = 0;
for (int i = 1;i <= k;i++) {
if (!was[i])
was[i] = skim(i);
ss += was[i];
}
if (ss > 2 * a)
impossible();
int ptr = n, d = 0;
while (sum > 2 * a) {
sum -= was[ptr];
sum += was[n - ptr + 1];
ptr--;
d++;
}
for (int i = 1;i <= d;i++)
ans.push_back(i);
for (int i = n - k + 1;i <= ptr;i++)
ans.push_back(i);
assert(sum >= a && sum <= 2 * a);
answer(ans);
}
else if (lst < k)
impossible();
for (int i = 1;i <= k - 1;i++) {
was[i] = skim(i);
sum += was[i];
}
sum += was[lst];
if (sum >= a && sum <= 2 * a) {
for (int i = 1;i <= k - 1;i++)
ans.push_back(i);
ans.push_back(lst);
answer(ans);
}
sum -= was[lst];
long long t = a - sum;
if (sum > a) {
was[k] = skim(k);
sum = 0;
for (int i = 1;i <= k;i++) {
ans.push_back(i);
sum += was[i];
}
if (sum >= a && sum <= 2 * a)
answer(ans);
assert(sum > 2 * a);
impossible();
}
int ll = k - 1;
l = k, r = lst - 1;
int id = -1;
while (l <= r) {
int mid = (l + r) / 2;
long long b = 0;
if (was[mid])
b = was[mid];
else
b = skim(mid);
was[mid] = b;
if (b < t) {
id = mid;
l = mid + 1;
}
else
r = mid - 1;
}
if (id == -1 || id + 1 == lst)
impossible();
for (int i = 1;i <= k - 1;i++)
ans.push_back(i);
ans.push_back(id + 1);
long long ss = sum + skim(id + 1);
assert(ss >= a && ss <= 2 * a);
answer(ans);
}
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... |