#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long ll;
const int lim = 1e5 + 5;
ll cost[lim];
ll get(int i){
if(cost[i] != -1){
return cost[i];
}
return cost[i] = skim(i);
}
void solve(int n, int k, ll A, int S){
memset(cost, -1, sizeof(cost));
if(S == n){
for(int i = 1; i <= n; i++){
get(i);
}
ll pref = accumulate(cost + 1, cost + k + 1, 0LL);
if(pref > (A << 1LL)){
impossible();
return;
}
vector<int>ans;
if(pref >= A){
for(int i = 1; i <= k; i++){
ans.push_back(i);
}
answer(ans);
return;
}
ll sum = pref;
for(int i = n, j = k; i > j && j > 0; i--){
ll alt = sum - cost[j] + cost[i];
if(alt <= (A << 1LL)){
if(alt >= A){
for(int t = j - 1; t > 0; t--){
ans.push_back(t);
}
ans.push_back(i);
answer(ans);
return;
}
pref -= cost[j--];
sum = alt;
ans.push_back(i);
}
}
impossible();
return;
}
if(S >= 170){
ll pref = 0;
for(int i = 1; i <= n; i++){
pref += get(i);
}
if(pref > (A << 1LL)){
impossible();
return;
}
vector<int>ans;
if(pref >= A){
for(int i = 1; i <= k; i++){
ans.push_back(i);
}
answer(ans);
return;
}
ll sum = pref;
for(int j = k, pre = n; j > 0; j--){
int low = j + 1, high = pre - 1, i = -1;
while(low <= high){
int mid = (low + high) >> 1;
if(sum - get(j) + get(mid) <= (A << 1LL)){
low = (i = mid) + 1;
}
else{
high = mid - 1;
}
}
if(i == -1){
impossible();
}
ll alt = sum - cost[j] + cost[i];
if(alt >= A){
for(int t = j - 1; t > 0; t--){
ans.push_back(t);
}
ans.push_back(i);
answer(ans);
return;
}
pref -= cost[j];
sum = alt;
ans.push_back(pre = i);
}
impossible();
return;
}
}
| # | 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... |