#include "shortcut.h"
#include <algorithm>
#include <functional>
using namespace std;
typedef long long llong;
typedef pair<llong, llong> pll;
int n, c;
vector<llong> S;
vector<int> D;
vector<pll> Mord;
vector<pll> Pord;
vector<pll> Pmn1;
vector<llong> Pmn2;
const llong inf = 1e18;
int check(llong X) {
llong mxP = -inf, mxM = -inf;
llong mnP = inf, mnM = inf;
for (int i = 0, j = 0; i < n; ++i) {
llong it, v;
tie(v, it) = Mord[i];
while (j < n && Pord[j].first <= X + v) ++j;
llong mP = -inf;
for (int k = n - 1; j <= k; --k) if (Pord[k].second != it) {
mP = Pord[k].first;
break;
}
llong mM = (j < n ?
(Pmn1[j].second != it ? Pmn1[j].first : Pmn2[j]) : inf);
mxP = max(mxP, S[it] + D[it] + mP - (X - c));
mxM = max(mxM, S[it] + D[it] - mM - (X - c));
mnP = min(mnP, v + mM + (X - c));
mnM = min(mnM, v - mP + (X - c));
if (mnP < mxP) return 0;
if (mnM < mxM) return 0;
}
for (int i = 0, mn = 0, mx = 0; i < n; ++i) {
llong LB = max(mxP - S[i], S[i] - mnM);
llong UB = max(mnP - S[i], S[i] - mxM);
while (mn < n && S[mn] < LB) ++mn;
while (0 < mn && LB <= S[mn - 1]) --mn;
while (mx < n && S[mx] <= UB) ++mx;
while (0 < mx && UB < S[mx - 1]) --mx;
if (mn < mx) return 1;
}
return 0;
}
llong find_shortcut(int N, vector<int> L, vector<int> E, int C) {
n = N; c = C;
S.push_back(0);
for (int i : L) S.push_back(S.back() + i);
D = E;
for (int i = 0; i < n; ++i) {
Mord.emplace_back(S[i] - D[i], i);
Pord.emplace_back(S[i] + D[i], i);
}
sort(Mord.begin(), Mord.end());
sort(Pord.begin(), Pord.end());
Pmn1.resize(n, pll(inf, -1)); Pmn2.resize(n, inf);
for (int i = n; i--; ) {
int it = Pord[i].second;
llong v = S[it] - D[it];
if (v < Pmn1[i].first) Pmn2[i] = Pmn1[i].first, Pmn1[i] = pll(v, it);
else if (v < Pmn2[i]) Pmn2[i] = v;
if (i) Pmn1[i - 1] = Pmn1[i], Pmn2[i - 1] = Pmn2[i];
}
sort(E.begin(), E.end());
llong s = E[n - 2] + E[n - 1], e = inf;
while (s < e) {
llong m = (s + e) / 2;
if (check(m)) e = m;
else s = m + 1;
}
return s;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
500 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
564 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
564 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
564 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
564 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
564 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
564 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
564 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
564 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
564 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
564 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
564 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
500 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
564 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
564 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
564 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
564 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
564 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
564 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
564 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
564 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
564 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
564 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
564 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
500 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
564 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
564 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
564 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
564 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
564 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
564 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
564 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
564 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
564 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
564 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
564 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
500 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
564 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
564 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
564 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
564 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
564 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
564 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
564 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
564 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
564 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
564 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
564 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
500 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
564 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
564 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
564 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
564 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
564 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
564 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
564 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
564 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
564 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
564 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
564 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
500 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
564 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
564 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
564 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
564 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
564 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
564 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
564 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
564 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
564 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
564 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
564 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
500 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
564 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
564 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
564 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
564 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
564 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
564 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
564 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
564 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
564 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
564 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
564 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
500 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
564 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
564 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
564 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
564 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
564 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
564 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
564 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
564 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
564 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
564 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
564 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
564 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
564 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |