# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
406186 | shenxy | 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 "books.h"
#include <algorithm>
#include <vector>
using namespace std;
long long skim(int i){return i;}
void answer(vector<int> v){}
void impossible(){}
void solve(int N, int K, long long A, int S) {
if (skim(1) > A) impossible();
int l = 1, r = N;
while (l != r) {
if (skim((l + r) / 2 + 1) <= A) l = (l + r) / 2 + 1;
else r = (l + r) / 2;
}
vector<long long> x, pos;
if (r <= 2 * K) {
for (int i = 1; i <= r; ++i) pos.push_back(i), x.push_back(skim(i));
} else {
for (int i = 1; i <= K; ++i) pos.push_back(i), x.push_back(skim(i));
for (int i = r - K + 1; i <= r; ++i) pos.push_back(i), x.push_back(skim(i));
}
if (r != N && r >= K - 1) {
long long sum = 0;
for (int i = 0; i < K - 1; ++i) sum += x[i];
sum += skim(r + 1);
if (sum <= 2 * A) {
vector<int> ans;
for (int i = 1; i < K; ++i) ans.push_back(i);
ans.push_back(r + 1);
answer(ans);
}
}
if (r < K) impossible();
long long sum = 0;
for (int i = 0; i < K; ++i) sum += x[i];
if (sum > 2 * A) impossible();
if (sum >= A) {
vector<int> ans;
for (int i = 1; i <= K; ++i) ans.push_back(i);
answer(ans);
}
for (int i = K; i < x.size(); ++i) {
sum += x[i] - x[i - K];
if (sum >= A) {
vector<int> ans;
for (int j = i; j > i - K; --j) ans.push_back(j);
answer(ans);
}
}
impossible();
}