# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
787762 | 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 <= min(K, l - K); ++i)
v.pb({i, skim(i)});
for (int i = max(K + 1, l - K + 1); i <= l; ++i)
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();
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
return 0;
}