#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
typedef pair<int, int> pii;
#include "books.h"
constexpr int maxn = 1e5 + 5;
int n;
ll v[maxn + 1] = { 0 }, pref[maxn + 1] = { 0 };
bool correct;
int fnd(int k, ll lower, ll upper)
{
correct = false;
int l = 0, u = n - k, mid;
ll val;
// cout << lower << " " << upper << "\n";
while (l != u)
{
mid = (l + u) >> 1;
val = pref[mid + k] - pref[mid];
// cout << val << " ";
if (val < lower) l = mid + 1;
else if (val > upper) u = mid;
else {
correct = true;
// cout << "\n";
return mid;
}
}
// cout << "\n";
return l;
}
void solve(int N, int k, long long A, int s) {
n = N;
if (s != n) impossible();
for (int i = 1; i <= n; i++) v[i] = skim(i);
for (int i = 1; i <= n; i++) {
pref[i] = pref[i - 1] + v[i];
if (pref[i] >= (7ull << 61)) pref[i] = (7ull << 61);
}
vector <int> output;
ll lower = A, upper = 2 * A;
int nk = k;
int p;
while (output.size() != (ll)k)
{
p = fnd(nk, lower, upper);
// cout << p << " " << v[p + nk] << "\n";
if (v[p + nk] > upper) impossible();
if (correct) {
while (output.size() != (ll)k) output.emplace_back(++p);
upper = lower = 0;
} else {
if (!output.empty() && output.back() == p + nk) impossible();
output.emplace_back(p + nk);
upper -= v[p + nk];
if (lower <= v[p + nk]) lower = 0;
else lower -= v[p + nk];
nk--;
}
}
if (lower != 0) impossible();
answer(output);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
308 KB |
Output is correct |
2 |
Correct |
9 ms |
316 KB |
Output is correct |
3 |
Correct |
10 ms |
316 KB |
Output is correct |
4 |
Correct |
10 ms |
312 KB |
Output is correct |
5 |
Correct |
11 ms |
316 KB |
Output is correct |
6 |
Correct |
7 ms |
208 KB |
Output is correct |
7 |
Correct |
8 ms |
208 KB |
Output is correct |
8 |
Correct |
9 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
9 ms |
304 KB |
Output is correct |
3 |
Correct |
11 ms |
316 KB |
Output is correct |
4 |
Correct |
8 ms |
320 KB |
Output is correct |
5 |
Correct |
11 ms |
320 KB |
Output is correct |
6 |
Correct |
11 ms |
312 KB |
Output is correct |
7 |
Correct |
10 ms |
312 KB |
Output is correct |
8 |
Correct |
10 ms |
208 KB |
Output is correct |
9 |
Incorrect |
245 ms |
596 KB |
Incorrect |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |