#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.
//
const int maxn = 1e5+5;
long long d[maxn], l, r;
//vector <long long> v;
/*
void impossible(){
cout << -1 << endl;
return;
}
long long skim (int in){
return v[in - 1];
}
void answer (vector <int> ans){
for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
cout << endl;
return;
}*/
int find (int k, int N){
long long suma = 0;
for (int i = N; i >= N - k + 1; i--) suma += d[i];
if (suma < l) return -1;
if (suma <= r) return N;
suma = 0;
for (int i = 1; i <= k; i++) suma += d[i];
if (suma > r) return -1;
if (suma >= l) return k;
for (int i = k + 1; i <= N; i++){
suma -= d[i - k - 1];
suma += d[i];
if (suma >= l) return i;
}
}
void solve(int N, int K, long long A, int S) {
for (int i = 1; i <= N; i++) d[i] = skim(i);
vector <int> ans;
l = A, r = 2 * A;
for (int i = 0; i < K; i++){
int in = find(K - i, N);
//cout << i << " " << in << endl;
if (in == -1) impossible();
ans.push_back(in);
l-=d[in], r-=d[in];
N = in - 1;
}
//cout << "l r " << l << " " << r << endl;
if (l <= 0 and r >= 0) answer(ans);
else impossible();
return;
}
/*
int main (void){
v.push_back(1), v.push_back(2), v.push_back(4), v.push_back(5), v.push_back(9), v.push_back(20), v.push_back(25), v.push_back(30);
solve(8, 3, 32, 8);
return 0;
}*/
Compilation message
books.cpp: In function 'int find(int, int)':
books.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
51 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
336 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
336 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
448 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
448 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
448 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
448 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
448 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |