#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; t > 0; t--){
ans.push_back(t);
}
answer(ans);
return;
}
pref -= cost[j];
sum = alt;
ans.push_back(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... |