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;
void solve(int N, int K, long long A, int S) {
int lx = 1, rx = N;
vector<int> val(N + 1, -1);
int pos = N;
while (lx <= rx) {
int g = lx + (rx - lx) / 2;
val[g] = skim(g);
if (val[g] < A) {
lx = g + 1;
} else {
pos = g;
rx = g - 1;
}
}
for (int i = 1;i <= K;i ++)
val[i] = skim(i);
for (int i = pos - 1;i >= max(pos - K, 0);i --)
val[i] = skim(i);
if (pos < K) {
impossible();
return;
}
if (pos != -1 && pos >= K) {
int sm = 0;
vector<int> ans;
for (int i = 1;i <= K - 1;i ++) {
sm += val[i];
ans.push_back(i);
}
ans.push_back(pos);
if (sm + val[pos] >= A && sm + val[pos] <= 2 * A) {
answer(ans);
return;
}
}
vector<int> ind;
vector<int> values;
ind.push_back(-1);
values.push_back(-1);
for (int i = 1;i <= K;i ++) {
values.push_back(val[i]);
ind.push_back(i);
}
for (int i = max(pos - K, K + 1);i < pos;i ++) {
values.push_back(val[i]);
ind.push_back(i);
}
for (int i = 1;i <= K + 1;i ++) {
if ((int)values.size() - i >= K) {
int sm = 0;
vector<int> ans;
for (int j = 0;j < K;j ++) {
sm += values[i + j];
ans.push_back(ind[i + j]);
}
if (sm >= A && sm <= 2 * A) {
answer(ans);
return;
}
}
}
impossible();
}
# | 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... |