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 <vector>
#include <iostream>
using namespace std;
using ll = long long;
//
// --- 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) {
vector<int> a(K+1);
vector<ll> books(K);
ll sum = 0;
for (int i = 1; i <= K; i++) {
a[i] = i;
books[i] = skim(i);
sum += books[i];
}
if (sum > 2*A) {
impossible();
return;
}
if (sum >= A && sum <= 2*A) {
vector<int> ans(K);
for (int i = 1; i <= K; i++)
ans[i-1] = a[i];
answer(ans);
}
int idx = N;
for (int i = K; i >= 1; i--) {
// move the ith book to the end
sum -= books[i];
int x = skim(idx);
if (sum+x >= A && sum+x <= 2*A) {
a[i] = idx;
break;
}
else if (sum+x < A) {
sum += x;
books[i] = x;
a[i] = idx;
idx--;
}
else {
// cout << "HELLO\n";
int l = a[i], r = idx;
while (l < r) {
int mid = (l+r)/2;
int d = skim(mid);
if (sum+d >= A && sum+d <= 2*A) {
a[i] = mid;
break;
}
if (sum+d < A) {
l = mid+1;
}
else {
r = mid;
}
}
a[i] = (l+r)/2;
break;
}
}
vector<int> ans(K);
for (int i = 1; i <= K; i++) {
ans[i-1] = a[i];
}
answer(ans);
}
# | 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... |