#include "shortcut.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define N 100007
#define INF 1000000000007
ll a[10*N],b[10*N],a1[10*N],b1[10*N],t[10*N],ma[10*N],mb[10*N];
long long find_shortcut(int n, std::vector<int> k, std::vector<int> d, int c)
{
for(int i=1;i<n;i++){
a[i]=k[i-1];
b[i]=d[i-1];
t[i]=t[i-1]+a[i-1];
ma[i]=max(ma[i-1],a1[i-1]+a[i-1]+b[i]);
a1[i]=max(a1[i-1]+a[i-1],b[i]);
}
b[n]=d[n-1];
t[n]=t[n-1]+a[n-1];
ma[n]=max(ma[n-1],a1[n-1]+a[n-1]+b[n]);
a1[n]=max(a1[n-1]+a[n-1],b[n]);
for(int i=n;i>=1;i--){
mb[i]=max(mb[i+1],b1[i+1]+a[i]+b[i]);
b1[i]=max(b[i],b1[i+1]+a[i]);
}
b[n]=d[n-1];
ll prew=INF;
ll res=ma[n];
// cout<<res<<endl;
for(int l=1;l<=n;l++){
for(int r=l+1;r<=n;r++){
res=min(res,max(ma[r-1],max(mb[l+1],min(ll(c),t[r]-t[l])+a1[l]+b1[r])));
//cout<<l<<" "<<r<<" "<<res<<" "<<ma[r-1]<<" "<<mb[l+1]<<" "<<a1[l]<<" "<<b1[r]<<" "<<t[r]-t[l]<<endl;
}
}
return res;
}
Compilation message
shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:32:8: warning: unused variable 'prew' [-Wunused-variable]
32 | ll prew=INF;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
312 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
304 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
340 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
308 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
340 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
340 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
340 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
312 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
304 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
340 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
308 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
340 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
340 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
340 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
312 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
304 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
340 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
308 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
340 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
340 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
340 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
312 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
304 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
340 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
308 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
340 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
340 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
340 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
312 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
304 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
340 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
308 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
340 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
340 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
340 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
312 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
304 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
340 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
308 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
340 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
340 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
340 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
312 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
304 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
340 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
308 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
340 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
340 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
340 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
312 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
304 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
340 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
308 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
340 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
340 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
340 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
340 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |