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;
//
// --- 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.
//
typedef long long ll;
typedef vector<ll> vi;
#define sz(x) (int)(x).size()
ll A;
int N, K, S;
vi store;
ll mySkim(int x)
{
assert(1 <= x && x <= N);
if (store[x] == -1)
store[x] = skim(x);
return store[x];
}
void myImpossible() { impossible(); }
void myAnswer(vi &ans)
{
assert(sz(ans) == K);
ll checkSum = 0;
vector<int> yourAns;
for (ll x : ans)
yourAns.push_back((int)x), checkSum += mySkim((int)x);
assert(A <= checkSum && checkSum <= 2 * A);
answer(yourAns);
}
void solve(int _N, int _K, long long _A, int _S)
{
A = _A, N = _N, K = _K, S = _S;
store.assign(N + 1, -1); // starting with 1 index
for (int i = 1; i <= N; ++i)
mySkim(i);
ll psum = 0;
for (int i = 1; i <= K; ++i)
psum += mySkim(i);
if (psum > 2 * A)
myImpossible();
int idx = 1;
while (idx + K <= N && psum < A)
{
psum -= mySkim(idx);
psum += mySkim(idx + K);
++idx;
}
if (psum > 2 * A)
{
assert(mySkim(idx + K - 1) > A);
vi ans;
psum = 0;
for (int i = 1; i <= K - 1; ++i)
ans.push_back(i), psum += mySkim(i);
ans.push_back(idx + K - 1), psum += mySkim(idx + K - 1);
if (psum <= 2 * A)
myAnswer(ans);
else
myImpossible();
}
else if (psum >= A)
{
vi ans;
for (int i = idx; i < idx + K; ++i)
ans.push_back(i);
myAnswer(ans);
}
else
myImpossible();
}
# | 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... |