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 "books.h"
#include <bits/stdc++.h>
typedef long long ll;
void solve(int n, int k, ll a, int s) {
std::vector <ll> vals(n + 1, -1);
ll sumfirst = 0;
for (int i = 1; i <= k - 1; i++) {
vals[i] = skim(i);
sumfirst += vals[i];
}
int l = k + 1, r = n;
int best = k;
while (l <= r) {
int mid = (l + r) >> 1;
ll now = skim(mid);
vals[mid] = now;
ll total = now + sumfirst;
if (total >= a + a) {
r = mid - 1;
} else {
l = mid + 1;
best = mid;
}
}
if (best == k && sumfirst + vals[best] > a + a) {
impossible();
return;
}
if (sumfirst + vals[best] >= a) {
std::vector <int> ans;
for (int i = 1; i <= k - 1; i++) ans.push_back(i);
ans.push_back(best);
answer(ans);
return;
}
std::vector <int> ans;
for (int i = 1; i <= k - 1; i++) ans.push_back(i);
ans.push_back(best);
std::set <int> have;
for (int x : ans) have.insert(x);
ll sum = sumfirst + vals[best];
int cur = best;
for (int i = 1 - 1; i <= k - 1 - 1; i++) {
sum -= vals[ans[i]];
have.erase(ans[i]);
int nw = --cur;
if (have.count(nw)) {
impossible();
return;
}
have.insert(nw);
if (vals[nw] == -1LL) vals[nw] = skim(nw);
sum += vals[nw];
if (sum >= a) break;
}
std::vector <int> put;
for (int x : have) put.push_back(x);
answer(put);
}
# | 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... |