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"
typedef long long ll;
//less_equal for identical elements
//
// --- Sample implementation for the task books ---
//
// To compile this program with the sample grader, place:
// books.h books_sample.cpp sample_grader.cpp
// in a single folder and run:
// g++ books_sample.cpp sample_grader.cpp
// in this folder.
//
int n;
long long a[100005];
bool use[100005];
ll arr(int i){
if(a[i]!=0)return a[i];
else return a[i]=skim(i);
}
void done(){
vector<int> ans;
for(int i=1;i<=n;++i){
if(use[i])ans.push_back(i);
}
answer(ans);
}
void solve(int N, int K, long long A, int S) {
n=N;
ll sm=0;
for(int i=1;i<=K;++i){
sm+=arr(i);
use[i]=true;
}
if(A<=sm&&sm<=2*A)done();
else if(sm>2*A)impossible();
int lo=1,hi=N,mid,res=0;
while(lo<=hi){
mid=(lo+hi)/2;
if(arr(mid)<=A){
res=mid;
lo=mid+1;
}
else hi=mid-1;
}
if(res<=K)impossible();
for(int i=K;i>=1;--i){
if(sm-arr(i)+arr(res-(K-i))<=2*A){
sm=sm-arr(i)+arr(res-(K-i));
use[i]=false;
use[res-(K-i)]=true;
}
}
if(A<=sm)done();
else if(res==N)impossible();
sm=0;
memset(use,false,sizeof use);
for(int i=1;i<=K-1;++i){
sm+=arr(i);
use[i]=true;
}
use[res+1]=true;
sm+=arr(res+1);
for(int i=K-1;i>=1;--i){
if(sm-arr(i)+arr(res-(K-1-i))<=2*A){
sm=sm-arr(i)+arr(res-(K-1-i));
use[i]=false;
use[res-(K-1-i)]=true;
}
}
if(sm<A||sm>2*A)impossible();
else done();
}
# | 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... |