# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
467855 | JovanB | A Difficult(y) Choice (BOI21_books) | C++17 | 1 ms | 288 KiB |
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"
using namespace std;
using ll = long long;
void solve(int N, int K, long long A, int S) {
vector <pair <ll, int>> vals;
int l = 1, r = N, gde = N+1;
while(l <= r){
int mid = (l+r)/2;
if(skim(mid) >= A){
r = mid - 1;
gde = mid;
}
else l = mid + 1;
}
if(gde < K){
impossible();
return;
}
for(int i=1; i<=min(K, gde-1); i++) vals.push_back({skim(i), i});
ll sum = 0;
if(gde <= N){
for(int i=0; i<K-1; i++) sum += vals[i].first;
sum += skim(gde);
if(A <= sum && sum <= 2*A){
vector <int> res;
for(int j=0; j<K-1; j++) res.push_back(vals[j].second);
res.push_back(gde);
answer(res);
return;
}
}
for(int i=max(gde-K, K+1); i<gde; i++) vals.push_back({skim(i), i});
sum = 0;
for(int i=0; i<K; i++) sum += vals[i].first;
if(A <= sum && sum <= 2*A){
vector <int> res;
for(int j=0; j<K; j++) res.push_back(vals[j].second);
answer(res);
return;
}
for(int i=K; i<vals.size(); i++){
sum -= vals[i-K].first;
sum += vals[i].first;
if(A <= sum && sum <= 2*A){
vector <int> res;
for(int j=i-K+1; j<=i; j++) res.push_back(vals[j].second);
answer(res);
return;
}
}
impossible();
}
Compilation message (stderr)
# | 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... |