# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
787766 | fabijan_cikac | 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 "books.h"
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int, ll>
#define F first
#define S second
#define ll long long
#define pb push_back
void solve(int N, int K, ll A, int S){
int l = 1, r = N;
while (l < r){
int mid = (l + r - 1) / 2;
if (skim(mid) >= A)
r = mid;
else l = mid + 1;
}
vector<pp> v;
for (int i = 1; i <= l; ++i){
if (i <= k || i >= l - k + 1)
v.pb({i, skim(i)});
}
for (int i = 0; i < (1 << (int)(v.size())); ++i){
if (__builtin_popcount(i) != K)
continue;
ll sum = 0;
for (int j = 0; j < v.size(); ++j){
if (i & (1 << j)) sum += v[j].S;
}
if (sum >= A && sum <= 2 * A){
vector<int> ans;
for (int j = 0; j < v.size(); ++j){
if (i & (1 << j)) ans.pb(v[j].F);
}
sort(ans.begin(), ans.end()); answer(ans);
}
}
impossible();
}