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.
//
#define ll long long
int n, k, s;
ll a;
vector<ll> v, pre;
vector<int> ans;
bool ended;
void generate(int idx, int prev, ll sum) {
if (ended) return;
if (sum > a*2) return;
if (n-prev < k-idx) return;
if (sum + pre[n] - pre[n-(k-idx)] < a) return;
if (idx == k) {
if (a <= sum && sum <= a*2) {
ended = 1;
return;
}
return;
}
for (int i = prev+1; i <= n; i++) {
if (v[i] - v[prev] <= a) continue;
ans[idx] = i;
generate(idx+1, i, sum + v[i]);
if (ended) return;
}
}
void solve(int N, int K, long long A, int S) {
// TODO implement this function
// impossible()
// answer()
// puedo hacer S preguntas
// hay N libros
// ordenados de mayor a menor por precio
// tengo que comprar K
// y la suma tiene que ser >= A y <= A*2
n = N;
k = K;
a = A;
s = S;
v.resize(n+1);
pre.resize(n+1, 0);
for (int i = 1; i <= n; i++) {
v[i] = skim(i);
pre[i] = pre[i-1] + v[i];
}
ended = 0;
ans.resize(k);
generate(0, 0, 0ll);
if (!ended) impossible();
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... |