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 "bits/stdc++.h"
using namespace std;
#include "books.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define mod 1000000007
void solve(int n, int k, ll a, int S) {
ll arr[n + 1];
for(int i = 1; i <= n; i++)
arr[i] = skim(i);
ll sum = 0;
for(int i = 1; i <= k; i++)
sum += arr[i];
vector<int> ans;
for(int i = 1; i <= k; i++)
ans.push_back(i);
if(sum >= a && sum <= 2 * a) {
answer(ans);
return;
}
if(sum < a) {
int L = k + 1, R = n;
for(int i = k; i >= 1; i--) {
int l = L, r = R;
while(l <= r) {
int mid = (l + r) / 2;
ll cur_sum = sum - arr[ans[i - 1]] + arr[mid];
if(cur_sum >= a && cur_sum <= 2 * a) {
ans[i - 1] = mid;
answer(ans);
return;
}
if(sum < a) {
l = mid + 1;
sum -= arr[ans[i - 1]];
sum += arr[mid];
ans[i - 1] = mid;
}
else
r = mid - 1;
}
L = i, R = ans[i - 1] - 1;
}
}
impossible();
}
# | 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... |