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>
#include "books.h"
using namespace std;
const int sz = 1e5 + 5;
long long q[sz];
long long get(long long x)
{
if(q[x])return q[x];
return q[x] = skim(x);
}
void solve(int n, int k, long long a, int s)
{
long long sum = 0;
vector<int> v;
for(int i = 1; i <= k; i++)
{
sum += get(i);
v.push_back(i);
}
if(sum > 2 * a)impossible();
if(a <= sum)answer(v);
int mx = 2 * a - (sum - get(k));
int l = k + 1, r = n, j = -1;
while(l <= r)
{
int m = (l + r) >> 1;
if(get(m) <= mx)l = m + 1, j = m;
else r = m - 1;
}
if(j == -1)impossible();
if(j < n + 1 && sum - get(k) + get(j) >= a)
{
v.pop_back();
v.push_back(j);
answer(v);
}
set<int> cur;
for(int i = 1; i <= k; i++)cur.insert(i);
for(int i = j; i > max(k, j - k); i--)
{
sum -= v[*cur.begin()];
cur.erase(cur.begin());
sum += get(j);
cur.insert(j);
if(sum >= a)
{
vector<int> ans;
for(int i : cur)ans.push_back(i);
answer(ans);
}
}
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... |