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 "books.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n,int k,long long a,int s){
int l = 1 , r = n , ans = n+1;
while(l<=r){
int mid = (l+r)/2;
if(skim(mid)>a){
ans = mid;
r = mid-1;
}else l = mid+1;
}
long long arr[k+1];
long long las[n+1];
long long all = 0;
for(int i= 1;i<=k;i++){
arr[i] = skim(i);
if(i<k){
all+=arr[i];
}
}
for(int i = min(ans,n);i>=max(1,ans-k);i--){
las[i] = skim(i);
}
if(ans<=n&&all+las[ans]>=a&&all+las[ans]<=2*a&&k-1+(ans>=k)==k){
vector<int> an;
for(int i = 1;i<k;i++)an.push_back(i);
an.push_back(ans);
answer(an);return ;
}
all = 0;
for(int i = 0;i<=k;i++){
if(i)all+=arr[k-i+1];
long long extra = 0 , cnt = 0;
for(int j = max((i?k+1:1),ans-k);j<min(ans,max((i?k+1:1),ans-k)+(k-i));j++){
extra+=las[j];
cnt++;
}
if(all+extra>=a&&all+extra<=2*a&&cnt+i==k){
vector<int> an;
for(int j = k;j>=k-i+1;j--)an.push_back(j);
for(int j = max((i?k+1:1),ans-k);j<max((i?k+1:1),ans-k)+(k-i);j++)an.push_back(j);
answer(an);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... |