#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
int n, l, x[201], t[201];
pii mom[205][205][2];
int32_t main(){
INIT
cin>>n>>l;
for(int i=1; i<=n; i++){
cin>>x[i];
}
for(int i=1; i<=n; i++){
cin>>t[i];
}
pii hlt={-1, -1};
for(int i=0; i<=(n+1); i++){
for(int j=0; j<=(n+1); j++){
mom[i][j][0]=mom[i][j][1]={-1, -1};
}
}
mom[n+1][0][0]={0, 0};
x[n+1]=l;
//0-dreapta, 1-stanga
int res=0;
for(int i=(n+1); i>=1; i--){
for(int j=0; j<i; j++){
mom[i][j][0]=max(mom[i][j][0], {mom[i][j][1].ft, -(-mom[i][j][1].sc+l-x[i]+x[j] ) } );
int cnt=mom[i][j][0].ft, ac=-mom[i][j][0].sc;
if(cnt>=0){
res=max(res, cnt);
for(int k=j+1, ac2=ac; k<i; k++){
ac2+=x[k]-x[k-1];
if(ac2<=t[k]){
mom[i][k][0]=max(mom[i][k][0], {cnt+1, -ac2});
}
else{
mom[i][k][0]=max(mom[i][k][0], {cnt, -ac2});
}
}
}
mom[i][j][1]=max(mom[i][j][1], {mom[i][j][0].ft, -(-mom[i][j][0].sc+x[j]+l-x[i]) } );
cnt=mom[i][j][1].ft, ac=-mom[i][j][1].sc;
if(cnt>=0){
res=max(res, cnt);
for(int k=i-1, ac2=ac; k>j; k--){
ac2+=x[k+1]-x[k];
if(ac2<=t[k]){
mom[k][j][1]=max(mom[k][j][1], {cnt+1, -ac2} );
}
else{
mom[k][j][1]=max(mom[k][j][1], {cnt, -ac2} );
}
}
}
}
}
cout<<res;
return 0;
}
Compilation message
ho_t3.cpp: In function 'int32_t main()':
ho_t3.cpp:28:5: warning: variable 'hlt' set but not used [-Wunused-but-set-variable]
28 | pii hlt={-1, -1};
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
0 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
0 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
0 ms |
336 KB |
Output is correct |
27 |
Correct |
0 ms |
324 KB |
Output is correct |
28 |
Correct |
0 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
0 ms |
336 KB |
Output is correct |
33 |
Correct |
0 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
1488 KB |
Output is correct |
19 |
Correct |
4 ms |
1104 KB |
Output is correct |
20 |
Correct |
2 ms |
976 KB |
Output is correct |
21 |
Correct |
3 ms |
1104 KB |
Output is correct |
22 |
Correct |
4 ms |
1232 KB |
Output is correct |
23 |
Correct |
1 ms |
848 KB |
Output is correct |
24 |
Correct |
1 ms |
848 KB |
Output is correct |
25 |
Correct |
1 ms |
840 KB |
Output is correct |
26 |
Correct |
1 ms |
592 KB |
Output is correct |
27 |
Correct |
1 ms |
848 KB |
Output is correct |
28 |
Correct |
2 ms |
720 KB |
Output is correct |
29 |
Incorrect |
2 ms |
836 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
0 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
0 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
0 ms |
336 KB |
Output is correct |
27 |
Correct |
0 ms |
324 KB |
Output is correct |
28 |
Correct |
0 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
0 ms |
336 KB |
Output is correct |
33 |
Correct |
0 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
0 ms |
336 KB |
Output is correct |
36 |
Correct |
6 ms |
1488 KB |
Output is correct |
37 |
Correct |
4 ms |
1104 KB |
Output is correct |
38 |
Correct |
2 ms |
976 KB |
Output is correct |
39 |
Correct |
3 ms |
1104 KB |
Output is correct |
40 |
Correct |
4 ms |
1232 KB |
Output is correct |
41 |
Correct |
1 ms |
848 KB |
Output is correct |
42 |
Correct |
1 ms |
848 KB |
Output is correct |
43 |
Correct |
1 ms |
840 KB |
Output is correct |
44 |
Correct |
1 ms |
592 KB |
Output is correct |
45 |
Correct |
1 ms |
848 KB |
Output is correct |
46 |
Correct |
2 ms |
720 KB |
Output is correct |
47 |
Incorrect |
2 ms |
836 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |