#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
int sum_order[N], diff_order[N], n;
long long sum[N], diff[N], x[N];
long long find_shortcut(int n, vector<int> l, vector<int> d, int c) {
::n = n;
for (int i = 0; i < n - 1; ++i) {
x[i + 1] = x[i] + l[i];
}
for (int i = 0; i < n; ++i) {
sum[i] = x[i] + d[i];
diff[i] = x[i] - d[i];
}
sort(d.rbegin(), d.rend());
iota(sum_order, sum_order + n, 0);
sort(sum_order, sum_order + n, [&](int a, int b) {
return sum[a] < sum[b];
});
iota(diff_order, diff_order + n, 0);
sort(diff_order, diff_order + n, [&](int a, int b) {
return diff[a] < diff[b];
});
long long low = d[0] + d[1], high = sum[sum_order[n - 1]] - diff[diff_order[0]];
while (low < high) {
long long mid = (low + high) / 2;
long long min_sum = LLONG_MIN, max_sum = LLONG_MAX;
long long min_diff = LLONG_MIN, max_diff = LLONG_MAX;
long long s = LLONG_MIN, d = LLONG_MAX;
for (int i = 0, j = 0; j < n; ++j) {
while (i < n && sum[sum_order[j]] - diff[diff_order[i]] > mid) {
s = max(s, sum[diff_order[i]]);
d = min(d, diff[diff_order[i]]);
++i;
}
if (sum[sum_order[j]] - diff[sum_order[j]] > mid) {
for (int k = 0; k < j; ++k) {
if (sum[j] - diff[k] > mid) {
min_sum = max(min_sum, -mid + c + sum[j] + sum[k]);
max_sum = min(max_sum, mid - c + diff[j] + diff[k]);
min_diff = max(min_diff, -mid + c + sum[j] - diff[k]);
max_diff = min(max_diff, mid - c + diff[j] - sum[k]);
}
}
} else if (s > LLONG_MIN) {
min_sum = max(min_sum, -mid + c + sum[sum_order[j]] + s);
max_sum = min(max_sum, mid - c + diff[sum_order[j]] + d);
min_diff = max(min_diff, -mid + c + sum[sum_order[j]] - d);
max_diff = min(max_diff, mid - c + diff[sum_order[j]] - s);
}
}
bool ok = false;
int l1 = n - 1, l2 = 0, r1 = n - 1, r2 = 0;
for (int i = 0; i < n; ++i) {
while (l1 >= 0 && x[i] + x[l1] >= min_sum) {
--l1;
}
while (r1 >= 0 && x[i] + x[r1] > max_sum) {
--r1;
}
while (l2 < n && x[i] - x[l2] > max_diff) {
++l2;
}
while (r2 < n && x[i] - x[r2] >= min_diff) {
++r2;
}
ok |= max(l1 + 1, l2) < min(r1 + 1, r2);
}
if (ok) {
high = mid;
} else {
low = mid + 1;
}
}
return low;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
332 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
332 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
332 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
332 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
332 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
332 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
332 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
332 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
332 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
332 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
332 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
332 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
332 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
332 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
332 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
332 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
332 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
332 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
332 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
332 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
332 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
332 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
332 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
332 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
332 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
332 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
332 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
332 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
332 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
332 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
332 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
332 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
332 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
332 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
332 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
332 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
332 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
332 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
332 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
332 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
332 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
332 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
332 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
332 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
332 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
332 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
332 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
332 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |