#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 200;
const ll INF = 1e18;
int N, L, X[MAXN+10], T[MAXN+10], ans;
ll dp1[MAXN+10][MAXN+10][MAXN+10], dp2[MAXN+10][MAXN+10][MAXN+10];
int main()
{
scanf("%d%d", &N, &L);
for(int i=1; i<=N; i++) scanf("%d", &X[i]);
for(int i=1; i<=N; i++) scanf("%d", &T[i]);
X[N+1]=L;
for(int i=0; i<=N; i++)
{
for(int j=N+1; j>=i+1; j--)
{
for(int k=0; k<=N; k++)
{
if(i==0 && j==N+1)
{
if(k==0) dp1[i][j][k]=dp2[i][j][k]=0;
else dp1[i][j][k]=dp2[i][j][k]=INF;
continue;
}
ll t=INF;
if(i>=1)
{
if(k && dp1[i-1][j][k-1]+X[i]-X[i-1]<=T[i]) t=min(t, dp1[i-1][j][k-1]+X[i]-X[i-1]);
if(dp1[i-1][j][k]+X[i]-X[i-1]>T[i]) t=min(t, dp1[i-1][j][k]+X[i]-X[i-1]);
if(k && dp2[i-1][j][k-1]+L-X[j]+X[i]<=T[i]) t=min(t, dp2[i-1][j][k-1]+L-X[j]+X[i]);
if(dp2[i-1][j][k]+L-X[j]+X[i]>T[i]) t=min(t, dp2[i-1][j][k]+L-X[j]+X[i]);
}
dp1[i][j][k]=t;
t=INF;
if(j<=N)
{
if(k && dp2[i][j+1][k-1]+X[j+1]-X[j]<=T[j]) t=min(t, dp2[i][j+1][k-1]+X[j+1]-X[j]);
if(dp2[i][j+1][k]+X[j+1]-X[j]>T[j]) t=min(t, dp2[i][j+1][k]+X[j+1]-X[j]);
if(k && dp1[i][j+1][k-1]+X[i]+L-X[j]<=T[j]) t=min(t, dp1[i][j+1][k-1]+X[i]+L-X[j]);
if(dp1[i][j+1][k]+X[i]+L-X[j]>T[j]) t=min(t, dp1[i][j+1][k]+X[i]+L-X[j]);
}
dp2[i][j][k]=t;
if(dp1[i][j][k]!=INF) ans=max(ans, k);
if(dp2[i][j][k]!=INF) ans=max(ans, k);
//if(j==11) printf("%d %d %d : %lld %lld\n", i, j, k, dp1[i][j][k], dp2[i][j][k]);
}
}
}
printf("%d\n", ans);
}
Compilation message
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
16 | scanf("%d%d", &N, &L);
| ~~~~~^~~~~~~~~~~~~~~~
ho_t3.cpp:17:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
17 | for(int i=1; i<=N; i++) scanf("%d", &X[i]);
| ~~~~~^~~~~~~~~~~~~
ho_t3.cpp:18:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
18 | for(int i=1; i<=N; i++) scanf("%d", &T[i]);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
640 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
488 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
768 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
640 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
488 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
768 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
768 KB |
Output is correct |
19 |
Correct |
1 ms |
640 KB |
Output is correct |
20 |
Correct |
1 ms |
768 KB |
Output is correct |
21 |
Correct |
1 ms |
768 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
896 KB |
Output is correct |
24 |
Correct |
1 ms |
768 KB |
Output is correct |
25 |
Correct |
1 ms |
768 KB |
Output is correct |
26 |
Correct |
1 ms |
768 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
896 KB |
Output is correct |
30 |
Correct |
1 ms |
896 KB |
Output is correct |
31 |
Correct |
1 ms |
768 KB |
Output is correct |
32 |
Correct |
1 ms |
768 KB |
Output is correct |
33 |
Correct |
1 ms |
896 KB |
Output is correct |
34 |
Correct |
1 ms |
896 KB |
Output is correct |
35 |
Correct |
1 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
640 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
488 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
768 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
59 ms |
55416 KB |
Output is correct |
19 |
Correct |
32 ms |
33912 KB |
Output is correct |
20 |
Correct |
15 ms |
18304 KB |
Output is correct |
21 |
Correct |
30 ms |
32000 KB |
Output is correct |
22 |
Correct |
40 ms |
41340 KB |
Output is correct |
23 |
Correct |
13 ms |
15616 KB |
Output is correct |
24 |
Correct |
10 ms |
12416 KB |
Output is correct |
25 |
Correct |
12 ms |
15360 KB |
Output is correct |
26 |
Correct |
4 ms |
6144 KB |
Output is correct |
27 |
Correct |
13 ms |
16000 KB |
Output is correct |
28 |
Correct |
9 ms |
11520 KB |
Output is correct |
29 |
Correct |
17 ms |
16256 KB |
Output is correct |
30 |
Correct |
10 ms |
12928 KB |
Output is correct |
31 |
Correct |
13 ms |
15356 KB |
Output is correct |
32 |
Correct |
6 ms |
8448 KB |
Output is correct |
33 |
Correct |
12 ms |
15360 KB |
Output is correct |
34 |
Correct |
4 ms |
5760 KB |
Output is correct |
35 |
Correct |
12 ms |
14976 KB |
Output is correct |
36 |
Correct |
5 ms |
7424 KB |
Output is correct |
37 |
Correct |
13 ms |
16000 KB |
Output is correct |
38 |
Correct |
7 ms |
8960 KB |
Output is correct |
39 |
Correct |
13 ms |
16640 KB |
Output is correct |
40 |
Correct |
8 ms |
9984 KB |
Output is correct |
41 |
Correct |
76 ms |
68088 KB |
Output is correct |
42 |
Correct |
47 ms |
46200 KB |
Output is correct |
43 |
Correct |
77 ms |
68088 KB |
Output is correct |
44 |
Correct |
44 ms |
45560 KB |
Output is correct |
45 |
Correct |
75 ms |
68088 KB |
Output is correct |
46 |
Correct |
45 ms |
46072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
640 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
488 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
768 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
768 KB |
Output is correct |
19 |
Correct |
1 ms |
640 KB |
Output is correct |
20 |
Correct |
1 ms |
768 KB |
Output is correct |
21 |
Correct |
1 ms |
768 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
896 KB |
Output is correct |
24 |
Correct |
1 ms |
768 KB |
Output is correct |
25 |
Correct |
1 ms |
768 KB |
Output is correct |
26 |
Correct |
1 ms |
768 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
896 KB |
Output is correct |
30 |
Correct |
1 ms |
896 KB |
Output is correct |
31 |
Correct |
1 ms |
768 KB |
Output is correct |
32 |
Correct |
1 ms |
768 KB |
Output is correct |
33 |
Correct |
1 ms |
896 KB |
Output is correct |
34 |
Correct |
1 ms |
896 KB |
Output is correct |
35 |
Correct |
1 ms |
896 KB |
Output is correct |
36 |
Correct |
59 ms |
55416 KB |
Output is correct |
37 |
Correct |
32 ms |
33912 KB |
Output is correct |
38 |
Correct |
15 ms |
18304 KB |
Output is correct |
39 |
Correct |
30 ms |
32000 KB |
Output is correct |
40 |
Correct |
40 ms |
41340 KB |
Output is correct |
41 |
Correct |
13 ms |
15616 KB |
Output is correct |
42 |
Correct |
10 ms |
12416 KB |
Output is correct |
43 |
Correct |
12 ms |
15360 KB |
Output is correct |
44 |
Correct |
4 ms |
6144 KB |
Output is correct |
45 |
Correct |
13 ms |
16000 KB |
Output is correct |
46 |
Correct |
9 ms |
11520 KB |
Output is correct |
47 |
Correct |
17 ms |
16256 KB |
Output is correct |
48 |
Correct |
10 ms |
12928 KB |
Output is correct |
49 |
Correct |
13 ms |
15356 KB |
Output is correct |
50 |
Correct |
6 ms |
8448 KB |
Output is correct |
51 |
Correct |
12 ms |
15360 KB |
Output is correct |
52 |
Correct |
4 ms |
5760 KB |
Output is correct |
53 |
Correct |
12 ms |
14976 KB |
Output is correct |
54 |
Correct |
5 ms |
7424 KB |
Output is correct |
55 |
Correct |
13 ms |
16000 KB |
Output is correct |
56 |
Correct |
7 ms |
8960 KB |
Output is correct |
57 |
Correct |
13 ms |
16640 KB |
Output is correct |
58 |
Correct |
8 ms |
9984 KB |
Output is correct |
59 |
Correct |
76 ms |
68088 KB |
Output is correct |
60 |
Correct |
47 ms |
46200 KB |
Output is correct |
61 |
Correct |
77 ms |
68088 KB |
Output is correct |
62 |
Correct |
44 ms |
45560 KB |
Output is correct |
63 |
Correct |
75 ms |
68088 KB |
Output is correct |
64 |
Correct |
45 ms |
46072 KB |
Output is correct |
65 |
Correct |
67 ms |
61560 KB |
Output is correct |
66 |
Correct |
62 ms |
56568 KB |
Output is correct |
67 |
Correct |
57 ms |
54136 KB |
Output is correct |
68 |
Correct |
51 ms |
50040 KB |
Output is correct |
69 |
Correct |
83 ms |
60920 KB |
Output is correct |
70 |
Correct |
65 ms |
58488 KB |
Output is correct |
71 |
Correct |
62 ms |
59128 KB |
Output is correct |
72 |
Correct |
65 ms |
59640 KB |
Output is correct |
73 |
Correct |
58 ms |
55416 KB |
Output is correct |
74 |
Correct |
53 ms |
51832 KB |
Output is correct |
75 |
Correct |
63 ms |
57208 KB |
Output is correct |
76 |
Correct |
76 ms |
65504 KB |
Output is correct |
77 |
Correct |
71 ms |
65400 KB |
Output is correct |
78 |
Correct |
52 ms |
50688 KB |
Output is correct |
79 |
Correct |
54 ms |
52344 KB |
Output is correct |
80 |
Correct |
74 ms |
64248 KB |
Output is correct |
81 |
Correct |
55 ms |
52984 KB |
Output is correct |
82 |
Correct |
59 ms |
55928 KB |
Output is correct |
83 |
Correct |
76 ms |
68088 KB |
Output is correct |
84 |
Correct |
64 ms |
58492 KB |
Output is correct |
85 |
Correct |
69 ms |
63608 KB |
Output is correct |
86 |
Correct |
68 ms |
62204 KB |
Output is correct |
87 |
Correct |
62 ms |
57212 KB |
Output is correct |
88 |
Correct |
80 ms |
68728 KB |
Output is correct |
89 |
Correct |
83 ms |
68908 KB |
Output is correct |
90 |
Correct |
60 ms |
57848 KB |
Output is correct |
91 |
Correct |
78 ms |
68728 KB |
Output is correct |
92 |
Correct |
76 ms |
68784 KB |
Output is correct |
93 |
Correct |
73 ms |
67448 KB |
Output is correct |