# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
773031 | Imeon | 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;
long long x[100000 + 1];
int h(int j){
int sm1 = 0;
for (int i = j; i < j + k;i++){
x[i] = skim(i);
sm1 += x[i];
if (i > K){sm1 -= x[i - K];}
}
/* if (sm >= A and sm <= 2LL * A){
return 1;
}*/
return sm1;
}
void solve(int N, int K, long long A, int S) {
// cin >> N >> K >> S >> A;
long long sm = 0;
K--;
for (int i = 1; i <= K + 1;i++){
x[i] = skim(i);
if (i <= K)sm += x[i];
}
int l = K,r = N + 1;
while (l + 1 < r){
int md = (l + r) / 2;
if ((x[md] + sm) > 2ll * A)r = md;
else l = md;
}
K++;
sm += x[l];
if (l == K or sm > 2LL * A)impossible();
l = 0,r = N + 1;
while (l + 1 < r){
int md = (l + r) / 2;
if (h(md) > 2ll * A)r = md;
else l = md;
}
int d = 0;
vector<int>v1;
for (int i = l; i < l + K;i++){
d += x[i];
v1.push_back(j);
}
if (l == 0 or d > 2LL * A)impossible();
answer(v1);
impossible();
}