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;
typedef long long ll;
//
// --- 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, ll A, int S) {
int l = 0, r = N, ans = -1;
while (l <= r){
if (l == r){
ans = l;
break;
}
int m = (l + r) >> 1;
ll res = skim(m);
if (res * K < A) l = m + 1;
else if (res * K > 2 * A) r = m - 1;
else{
ans = m;
break;
}
}
vector<pair<int, ll>> vec;
vec.push_back({ans, skim(ans)});
for (int k = 1; k <= 10 && ans - k >= 1; k++) vec.push_back({ans - k, skim(ans - k)});
for (int k = 1; k <= 10 && ans + k <= N; k++) vec.push_back({ans + k, skim(ans + k)});
sort(vec.begin(), vec.end());
int sz = vec.size();
vector<int> perm;
for (int i = sz - 1; i >= 0; i--) perm.push_back(i < K);
do{
ll ans = 0;
vector<int> vans;
for (int i = 0; i < sz; i++)
if (perm[i]){
vans.push_back(vec[i].first);
ans += vec[i].second;
}
if (ans >= A && ans <= 2 * A) answer(vans);
} while (next_permutation(perm.begin(), perm.end()));
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... |