#include <bits/stdc++.h>
#include "shortcut.h"
//#include "grader.cpp"
using namespace std ;
long long find_shortcut(int n, vector<int> dist, std::vector<int>s, int c)
{
long long pref[n+1] , suff[n+1] , distance[n+1] , Max1[n+1] , Max2[n+1] , farp[n+1] , fars[n+1] ;
pref[1] = s[0] * 1ll;
farp[1] = s[0] * 1ll ;
distance[1] = 0ll ;
for(int i = 2 ; i <= n ; ++i)
{
farp[i] = pref[i-1] + dist[i-2]*1ll + s[i-1] * 1ll;
pref[i] = max(pref[i-1]+dist[i-2]*1ll , s[i-1]*1ll) ;
distance[i] = distance[i-1] + dist[i-2] * 1ll ;
}
suff[n] = s[n-1] * 1ll;
fars[n] = s[n-1] * 1ll ;
for(int i = n-1 ; i >= 1 ; --i)
{
fars[i] = suff[i+1]+dist[i-1]*1ll+s[i-1]*1ll ;
suff[i] = max(suff[i+1]+dist[i-1]*1ll , s[i-1]*1ll) ;
}
long long ans = 1e18 , now = 0 , val;
for(int i = 1 ; i <= n ; ++i)
now = max(now , max(farp[i] , fars[i])) ;
ans = min(ans , now) ;
for(int i = 1 ; i <= n ; ++i)
{
Max1[i] = 0 , Max2[i] = 0 ;
for(int j = i+1 ; j <= n ; ++j)
{
Max1[j] = Max1[j-1] ;
Max2[j] = Max2[j-1] ;
val = c * 1ll ;
now = pref[i] + val + suff[j] ;
for(int k = 1 ; k <= i ; ++k)
now = max(now , farp[k]) ;
for(int k = j ; k <= n ; ++k)
now = max(now , fars[k]) ;
for(int k = i+1 ; k < j ; ++k)
{
now = max(now , min(farp[k] , pref[i] + val + distance[j] - distance[k] + s[k-1] * 1ll)) ;
now = max(now , min(fars[k] , suff[j] + val + distance[k] - distance[i] + s[k-1] * 1ll)) ;
long long a = Max1[j-1] + distance[k] + s[k-1] ;
long long b = Max2[j-1] + distance[j] - distance[k] + s[k-1] ;
now = max(now , min(a , b)) ;
}
Max1[j] = max(Max1[j] , s[j-1] - distance[j]) ;
Max2[j] = max(Max2[j] , s[j-1] + distance[j] - distance[i] + val) ;
ans = min(ans , now) ;
}
}
return ans ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
376 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
256 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
256 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
256 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
2 ms |
256 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
252 KB |
n = 5, 12 is a correct answer |
21 |
Incorrect |
2 ms |
256 KB |
n = 5, incorrect answer: jury 25 vs contestant 28 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
376 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
256 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
256 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
256 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
2 ms |
256 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
252 KB |
n = 5, 12 is a correct answer |
21 |
Incorrect |
2 ms |
256 KB |
n = 5, incorrect answer: jury 25 vs contestant 28 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
376 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
256 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
256 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
256 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
2 ms |
256 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
252 KB |
n = 5, 12 is a correct answer |
21 |
Incorrect |
2 ms |
256 KB |
n = 5, incorrect answer: jury 25 vs contestant 28 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
376 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
256 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
256 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
256 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
2 ms |
256 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
252 KB |
n = 5, 12 is a correct answer |
21 |
Incorrect |
2 ms |
256 KB |
n = 5, incorrect answer: jury 25 vs contestant 28 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
376 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
256 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
256 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
256 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
2 ms |
256 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
252 KB |
n = 5, 12 is a correct answer |
21 |
Incorrect |
2 ms |
256 KB |
n = 5, incorrect answer: jury 25 vs contestant 28 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
376 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
256 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
256 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
256 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
2 ms |
256 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
252 KB |
n = 5, 12 is a correct answer |
21 |
Incorrect |
2 ms |
256 KB |
n = 5, incorrect answer: jury 25 vs contestant 28 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
376 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
256 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
256 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
256 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
2 ms |
256 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
252 KB |
n = 5, 12 is a correct answer |
21 |
Incorrect |
2 ms |
256 KB |
n = 5, incorrect answer: jury 25 vs contestant 28 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
376 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
256 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
256 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
256 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
256 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
256 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
256 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
256 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
256 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
2 ms |
256 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
252 KB |
n = 5, 12 is a correct answer |
21 |
Incorrect |
2 ms |
256 KB |
n = 5, incorrect answer: jury 25 vs contestant 28 |
22 |
Halted |
0 ms |
0 KB |
- |