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"
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;
using ll = long long;
void solve(int n, int k, ll a, int s) {
vector<ll> is(n + 1, -1);
auto ask = [&](int i){
if(~is[i]) return is[i];
is[i] = skim(i);
return is[i];
};
int l = 1, r = n;
while(l < r){
int m = (l + r) >> 1;
if(a < ask(m)) r = m;
else l = m + 1;
}
int p = l;
if(p < k){
impossible();
return;
}
vector<ll> L, R;
for(int i=1;i<=k;i++){
L.push_back(ask(i));
}
for(int i=p-k+1;i<=p;i++){
R.push_back(ask(i));
}
if(accumulate(R.begin(), R.end(), 0ll) < a) { impossible(); return; }
if(accumulate(L.begin(), L.end(), 0ll) > a * 2) { impossible(); return; }
int fix=-1;
for(int i=1;i<=k;i++){
ll sum = 0;
for(int j=0;j<i;j++) sum += L[j];
for(int j=k-1;j>=i;j--) sum += R[j];
if(sum > 2 * a) continue;
fix = i; break;
}
if(fix == -1) { impossible(); return; }
ll sum = 0;
for(int j=0;j<fix-1;j++) sum += L[j];
for(int j=k-1;j>=fix;j--) sum += R[j];
l = fix, r = p - k + fix;
while(l < r){
int m = (l + r) >> 1;
if(ask(m) + sum < a) l = m + 1;
else r = m;
}
if(ask(l) + sum <= a * 2 && a <= ask(l) + sum){
vector<int> res;
for(int i=1;i<fix;i++) res.push_back(i);
res.push_back(l);
for(int i=p-k+fix+1;i<=p;i++) res.push_back(i);
answer(res);
return;
} else impossible();
}
/*
15 3 42 12
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
*/
# | 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... |