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 <iostream>
#include <vector>
using namespace std;
#include "books.h"
int findA(vector<long long>& books, long long A, int lower, int upper) {
if (books[lower] == -1) {
books[lower] = skim(lower + 1);
}
if (books[upper] == -1) {
books[upper] = skim(upper + 1);
}
if (books[lower] > A) {
return -1;
}
if (books[upper] <= A) {
return upper;
}
if (upper == lower) {
return lower;
}
int half = (upper - lower + 1) / 2;
books[lower + half] = skim(lower + half + 1);
if (books[lower + half] < A) return findA(books, A, lower + half, upper);
else return findA(books, A, lower, lower + half);
}
void solve(int N, int K, long long A, int S) {
if (K > N) {
impossible();
return;
}
vector<long long> books(N);
for (int i = 0; i < N; i++) {
books[i] = -1;
}
int posA = findA(books, A, 0, N - 1);
if (posA == -1) {
impossible();
}
else {
if (posA == (N - 1)) {
long long sum = 0;
vector<int> res;
for (int i = 0; i < K; i++) {
res.push_back(N - i);
if (books[i] == -1) {
books[i] = skim(i + 1);
}
sum += books[i];
}
if (sum < A) {
impossible();
}
answer(res);
}
else {
vector<int> res;
int lastPos = posA + 1 + K;
if (lastPos > N) {
lastPos = N;
}
for (int i = 0; i < K; i++) {
res.push_back(lastPos - i);
}
answer(res);
}
}
return;
}
# | 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... |