# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
667392 | someone | A Difficult(y) Choice (BOI21_books) | C++14 | 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 "books.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e5 + 42;
int nb = 0, book[MAXN];
int skim(int i) {
nb++;
cout << i << ' ' << book[i] << '\n';
return book[i];
}
void answer(vector<int> v) {
cout << "answer :";
for(int i : v)
cout << ' ' << i;
}
void impossible() {
cout << "impossible";
}
ll val[MAXN];
ll get(int i) {
if(val[i] == 0)
val[i] = skim(i);
return val[i];
}
void solve(int N, int K, ll A, int S) {
for(int i = 1; i <= N; i++)
get(i);
vector<int> ans;
ll sum = 0;
for(int i = 1; i <= K; i++)
sum += val[i];
int last = K;
for(int i = K; i <= N; i++) {
last = i;
if(i == N || sum + val[i+1] - val[K] > 2*A)
i = N+1;
}
for(int i = K; i > 0; i--) {
if(sum + val[last + i - K] - val[i] <= 2*A) {
sum += val[last + i - K] - val[i];
ans.push_back(last + i - K);
}
if(sum >= A) {
for(int j = 1; j < i; j++)
ans.push_back(j);
answer(ans);
return;
}
}
impossible();
}
signed main() {
int N, K, A, S;
cin >> N >> K >> A >> S;
for(int i = 1; i <= N; i++)
cin >> book[i];
solve(N, K, A, S);
}