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>
#define fs first
#define sc second
#include "books.h"
using namespace std;
void solve(int n, int k, long long a, int s) {
vector<pair<long long,int> > v;
long long p=0;
for(int i=1;i<k;i++){
v.push_back({skim(i),i});
p+=v.back().fs;
}
int l=k,r=n;
while(r>l){
int m=(l+r+1)/2;
long long z=skim(m)+p;
if(z>2*a){
r=m-1;
}
else if(a<=z){
vector<int> ans;
for(int i=1;i<k;i++){
ans.push_back(i);
}
ans.push_back(m);
answer(ans);
return;
}
else{
l=m;
}
}
vector<pair<long long,int> > c;
long long p2=0;
c.push_back({skim(l),l});
p2+=c.back().fs;
for(int i=l-1;i>l-k;i--){
c.push_back({skim(i),i});
p2+=c.back().fs;
}
if(p2>=a && 2*a>=p2){
vector<int> ans;
for(auto h:c){
ans.push_back(h.sc);
}
answer(ans);
return;
}
reverse(c.begin(),c.end());
for(int i=0;i<k-1;i++){
long long z=0;
for(int j=0;j<i;j++){
z+=v[j].fs;
}
for(int j=i;j<k;j++){
z+=c[j].sc;
}
if(2*a >= z && z>=a){
vector<int> ans;
for(int j=0;j<i;j++){
ans.push_back(v[j].sc);
}
for(int j=i;j<k;j++){
ans.push_back(c[j].sc);
}
answer(ans);
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... |