# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
944047 | thelegendary08 | 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 <bits/stdc++.h>
#include "books.h"
using namespace std;
//
// --- 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) {
vector<long long int>v(N);
for(int i = 1;i<=N;i++){
v[i-1] = skim(i);
}
ll sum = 0;
for(int i = 0;i<K;i++){
sum += v[i];
}
if(sum >= A && sum <= 2*A){
vector<int> ret;
for(int i = 1;i<=K;i++){
ret.push_back(i);
}
answer(ret);
}
if(sum > 2*A)impossible();
int crit = -1;
for(int i = 1;i<N - K + 1; i++){
sum -= v[i-1];
sum += v[i+K-1];
if(sum >= A && sum <= 2*A){
vector<int>ret;
for(int j = i;j<i+K;j++)ret.push_back(j + 1);
answer(ret);
}
if(sum >2*A){
crit = i;
break;
}
}
if(crit == -1)impossible();
else{
long long int s = 0;
for(int i = crit - 1;i<crit+K;i++){
s += v[i];
}
for(int i = crit-1;i<crit+K;i++){
if(s - v[i] <= 2*A && s-v[i] >= A){
vector<int>ret;
for(int j = crit - 1;j<crit+K;j++){
if(j != i){
ret.push_back(j+1);
}
}
answer(ret);
}
}
}
impossible();
}