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"
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define lli long long int
#define vv vector<lli>
#define pr pair<int,int>
#define print(a) cout<<a<<endl
#define f first
#define s second
using namespace std;
//
// --- 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.
//
bool check(lli sum, lli A){
return (sum>=A && sum<=2*A);
}
void solve(int N, int K, long long A, int S) {
vector<int> res;
vv one;
lli sum=0;
FOR(i,0,K){
one.push_back(skim(i+1));
sum+=one[i];
}
if (sum>=A && sum<=2*A){
FOR(i,1,K+1)res.push_back(i);
answer(res);return;
}
if (sum>2*A){
impossible();return;
}
int l=1;
int r=N;
long long a;
while(l+1<r){
int m=(l+r)>>1;
a=skim(m);
if (A<a)r=m;
else l=m;
}
if (skim(l)>=A)r=l;
///a=skim(r);///////
if (r<=K){
impossible();
return;
}
if (check(sum+a-one.back(),A)){
FOR(i,1,K+1)res.push_back(i);
res[K-1]=r;
answer(res);return;
}
vv two;
int sum2=0;
FOR(i,r-K,r){
a=skim(i);
two.push_back(a);
sum2+=a;
}
if (sum2>=A && sum2<=2*A){
FOR(i,r-K,r)res.push_back(i);
answer(res);return;
}
FOR(i,1,K+1)res.push_back(i);
FOR(i,0,K){
res[i]=r-K+i;
sum+=two[i]-one[i];
if (check(sum,A)){
answer(res);return;
}
}
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... |