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 pb push_back
#include "books.h"
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.
//
void solve(int n, int k, long long A, int S) {
// TODO implement this function
long long x = skim(k - 1);
if(x >= A){
impossible();
return;
}
vector <long long > a, b;
for(int i = 1; i <= k; i++){
a.pb(skim(i));
}
int l = 1, r = n + 1;
while(l + 1 < r){
int mid = (l + r) / 2;
if(skim(mid) >= A) r = mid;
else l = mid;
}
if(r != n + 1){
long long tot = 0;
for(int i= 0; i < k - 1; i++){
tot += a[i];
}
tot += skim(r);
if(tot <= 2 * A){
vector <int> vv;
for(int i = 0; i < k - 1; i++)
vv.pb(i + 1);
vv.pb(r);
answer(vv);
return;
}
}
for(int i = r - 1; i >= r - k; i--){
b.pb(skim(i));
}
for(int i = 0; i <= k; i++){
long long tot = 0;
for(int j = 0; j < i; j++) tot += a[j];
for(int j = 0; j < k - i; j++) tot += b[j];
if(tot >= A && tot <= 2 * A){
vector <int> ans;
for(int j = 0; j < i; j++) ans.pb(j + 1);
for(int j = 0; j < k - i; j++) ans.pb(r - j - 1);
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... |