#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];
}
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 = 0, 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 sum_1 = LLONG_MIN, sum_2 = LLONG_MIN;
long long diff_1 = LLONG_MAX, diff_2 = LLONG_MAX;
for (int i = 0, j = 0; j < n; ++j) {
while (i < n && sum[sum_order[j]] - diff[diff_order[i]] > mid) {
long long s = sum[diff_order[i]], d = diff[diff_order[i]];
++i;
if (s > sum_1) {
sum_2 = sum_1, sum_1 = s;
} else if (s > sum_2) {
sum_2 = s;
}
if (d < diff_1) {
diff_2 = diff_1, diff_1 = d;
} else if (d < diff_2) {
diff_2 = d;
}
}
long long s = sum[sum_order[j]] == sum_1 ? sum_2 : sum_1;
long long d = diff[sum_order[j]] == diff_1 ? diff_2 : diff_1;
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);
}
}
if (n <= 3000) {
long long alt_min_sum = LLONG_MIN, alt_max_sum = LLONG_MAX;
long long alt_min_diff = LLONG_MIN, alt_max_diff = LLONG_MAX;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (sum[j] - diff[i] > mid) {
alt_min_sum = max(min_sum, -mid + c + sum[j] + sum[i]);
alt_max_sum = min(max_sum, mid - c + diff[j] + diff[i]);
alt_min_diff = max(min_diff, -mid + c + sum[j] - diff[i]);
alt_max_diff = min(max_diff, mid - c + diff[j] - sum[i]);
}
}
}
assert(
alt_min_sum <= min_sum &&
alt_max_sum >= max_sum &&
alt_min_diff <= min_diff &&
alt_max_diff >= max_diff
);
}
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;
}\
Compilation message
shortcut.cpp:119:2: error: stray '\' in program
119 | }\
| ^