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;
long long n,k,a,s;
long long x[120001];
long long val(int idx)
{
if(x[idx]==0)x[idx]=skim(idx);
return x[idx];
}
void solve(int N,int K,long long A,int S)
{
n=N;
k=K;
a=A;
s=S;
int lidx=k,ridx=n,idx=0;
while(lidx<=ridx)
{
int m=(lidx+ridx)/2;
if(val(m)>=a)
{
idx=m;
ridx=m-1;
}
else lidx=m+1;
}
if(idx>=k)
{
long long fk=0;
for(int i=1; i<k; i++)
fk+=val(i);
if(fk+val(idx)>=a&&fk+val(idx)<=2*a)
{
vector<int> ans;
for(int i=1; i<k; i++)
ans.push_back(i);
ans.push_back(idx);
answer(ans);
return;
}
if(idx==k)
{
impossible();
return;
}
}
if(idx==0)idx=n;
else idx--;
long long sum=0;
for(int i=1;i<=k;i++)
sum+=val(i);
if(sum>=a&&sum<=2*a)
{
vector<int> ans;
for(int i=1;i<=k;i++)
ans.push_back(i);
answer(ans);
return;
}
int lf=1,rt=max(k+1,idx-k+1);
while(lf<=k&&rt<=idx&&sum<a)
{
sum-=val(lf);lf++;
sum+=val(rt);rt++;
if(sum>=a&&sum<=2*a)
{
vector<int> ans;
for(int i=lf;i<=k;i++)
ans.push_back(i);
for(int i=max(k+1,idx-k+1);i<rt;i++)
ans.push_back(i);
answer(ans);
return;
}
}
impossible();
}
/*
10 4 20 11
1 2 3 4 5 15 16 17 18 19
10 5 10 10
1 2 3 4 5 6 7 8 9 100
*/
# | 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... |