#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void ngha();
const int mod2=1e9+7;
const int mod1=998244353;
struct ib
{
int a;
int b;
};
struct icd
{
int a,b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e;
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
/// fin(task),fou(task);
//#endif
NHP
//modwwe
// cin>>res;
ngha(),down
checktime
}
int a[301];
int b[301];
int dp[207][207][207][2];
void ngha()
{
cin>>n>>k;
for(int i=1; i<=n; i++)
cin>>a[i];
for(int i=1; i<=n; i++)
cin>>b[i];
///n+1 la deo dung
for(int i=0; i<=n; i++)
for(int j=n+1; j>i; --j)
for(int z=0; z<=n; z++)
dp[i][j][z][0]=dp[i][j][z][1]=1e18;
dp[0][n+1][0][1]=0;
dp[0][n+1][0][0]=0;
a[n+1]=k;
for(int i=0; i<=n; i++)
for(int j=n+1; j>i; --j)
for(int z=0; z<=i+n+1-j; z++)
{
dp[i][j][z][1]=min(dp[i][j][z][0]+a[i]+k-a[j],dp[i][j][z][1]);
dp[i][j][z][0]=min(dp[i][j][z][0],dp[i][j][z][1]+a[i]+k-a[j]);
if(i!=n&&i+1<j)
{
if(dp[i][j][z][1]+a[i+1]-a[i]<=b[i+1])
dp[i+1][j][z+1][1]=min(dp[i+1][j][z+1][1],dp[i][j][z][1]+a[i+1]-a[i]);
else
dp[i+1][j][z][1]=min(dp[i+1][j][z][1],dp[i][j][z][1]+a[i+1]-a[i]);
}
if(j-1>i)
{
if(dp[i][j][z][0]+a[j]-a[j-1]<=b[j-1])
dp[i][j-1][z+1][0]=min(dp[i][j-1][z+1][0],dp[i][j][z][0]+a[j]-a[j-1]);
else
dp[i][j-1][z][0]=min(dp[i][j-1][z][0],dp[i][j][z][0]+a[j]-a[j-1]);
}
}
s2=0;
for(int i=0; i<=n; i++)
for(int z=0; z<=n; z++)
if(min(dp[i][i+1][z][0],dp[i][i+1][z][0])!=1e18)
{
s2=max(s2,z);
}
cout<<s2;
}
Compilation message
ho_t3.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4600 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8656 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6608 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8536 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4600 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8656 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6608 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8536 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
1 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10584 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
10584 KB |
Output is correct |
30 |
Correct |
1 ms |
10588 KB |
Output is correct |
31 |
Correct |
1 ms |
10588 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
1 ms |
10700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4600 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8656 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6608 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8536 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
47 ms |
121688 KB |
Output is correct |
19 |
Correct |
16 ms |
94812 KB |
Output is correct |
20 |
Correct |
10 ms |
70488 KB |
Output is correct |
21 |
Correct |
16 ms |
92864 KB |
Output is correct |
22 |
Correct |
22 ms |
105052 KB |
Output is correct |
23 |
Correct |
9 ms |
64344 KB |
Output is correct |
24 |
Correct |
8 ms |
55972 KB |
Output is correct |
25 |
Correct |
9 ms |
64188 KB |
Output is correct |
26 |
Correct |
6 ms |
39512 KB |
Output is correct |
27 |
Correct |
9 ms |
64088 KB |
Output is correct |
28 |
Correct |
8 ms |
53852 KB |
Output is correct |
29 |
Correct |
11 ms |
66140 KB |
Output is correct |
30 |
Correct |
8 ms |
57944 KB |
Output is correct |
31 |
Correct |
9 ms |
64092 KB |
Output is correct |
32 |
Correct |
6 ms |
45660 KB |
Output is correct |
33 |
Correct |
9 ms |
64092 KB |
Output is correct |
34 |
Correct |
5 ms |
37468 KB |
Output is correct |
35 |
Correct |
10 ms |
62044 KB |
Output is correct |
36 |
Correct |
5 ms |
43612 KB |
Output is correct |
37 |
Correct |
10 ms |
64092 KB |
Output is correct |
38 |
Correct |
6 ms |
47708 KB |
Output is correct |
39 |
Correct |
10 ms |
66140 KB |
Output is correct |
40 |
Correct |
7 ms |
49752 KB |
Output is correct |
41 |
Correct |
36 ms |
135888 KB |
Output is correct |
42 |
Correct |
21 ms |
111452 KB |
Output is correct |
43 |
Correct |
32 ms |
136024 KB |
Output is correct |
44 |
Correct |
21 ms |
111452 KB |
Output is correct |
45 |
Correct |
31 ms |
136028 KB |
Output is correct |
46 |
Correct |
21 ms |
111452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4600 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8656 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6608 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8536 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
1 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10584 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
10584 KB |
Output is correct |
30 |
Correct |
1 ms |
10588 KB |
Output is correct |
31 |
Correct |
1 ms |
10588 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
1 ms |
10700 KB |
Output is correct |
36 |
Correct |
47 ms |
121688 KB |
Output is correct |
37 |
Correct |
16 ms |
94812 KB |
Output is correct |
38 |
Correct |
10 ms |
70488 KB |
Output is correct |
39 |
Correct |
16 ms |
92864 KB |
Output is correct |
40 |
Correct |
22 ms |
105052 KB |
Output is correct |
41 |
Correct |
9 ms |
64344 KB |
Output is correct |
42 |
Correct |
8 ms |
55972 KB |
Output is correct |
43 |
Correct |
9 ms |
64188 KB |
Output is correct |
44 |
Correct |
6 ms |
39512 KB |
Output is correct |
45 |
Correct |
9 ms |
64088 KB |
Output is correct |
46 |
Correct |
8 ms |
53852 KB |
Output is correct |
47 |
Correct |
11 ms |
66140 KB |
Output is correct |
48 |
Correct |
8 ms |
57944 KB |
Output is correct |
49 |
Correct |
9 ms |
64092 KB |
Output is correct |
50 |
Correct |
6 ms |
45660 KB |
Output is correct |
51 |
Correct |
9 ms |
64092 KB |
Output is correct |
52 |
Correct |
5 ms |
37468 KB |
Output is correct |
53 |
Correct |
10 ms |
62044 KB |
Output is correct |
54 |
Correct |
5 ms |
43612 KB |
Output is correct |
55 |
Correct |
10 ms |
64092 KB |
Output is correct |
56 |
Correct |
6 ms |
47708 KB |
Output is correct |
57 |
Correct |
10 ms |
66140 KB |
Output is correct |
58 |
Correct |
7 ms |
49752 KB |
Output is correct |
59 |
Correct |
36 ms |
135888 KB |
Output is correct |
60 |
Correct |
21 ms |
111452 KB |
Output is correct |
61 |
Correct |
32 ms |
136024 KB |
Output is correct |
62 |
Correct |
21 ms |
111452 KB |
Output is correct |
63 |
Correct |
31 ms |
136028 KB |
Output is correct |
64 |
Correct |
21 ms |
111452 KB |
Output is correct |
65 |
Correct |
29 ms |
129884 KB |
Output is correct |
66 |
Correct |
25 ms |
123740 KB |
Output is correct |
67 |
Correct |
25 ms |
121692 KB |
Output is correct |
68 |
Correct |
23 ms |
115548 KB |
Output is correct |
69 |
Correct |
27 ms |
127836 KB |
Output is correct |
70 |
Correct |
27 ms |
125788 KB |
Output is correct |
71 |
Correct |
26 ms |
125788 KB |
Output is correct |
72 |
Correct |
27 ms |
127836 KB |
Output is correct |
73 |
Correct |
25 ms |
121692 KB |
Output is correct |
74 |
Correct |
23 ms |
117596 KB |
Output is correct |
75 |
Correct |
26 ms |
123740 KB |
Output is correct |
76 |
Correct |
31 ms |
131932 KB |
Output is correct |
77 |
Correct |
29 ms |
131932 KB |
Output is correct |
78 |
Correct |
23 ms |
117596 KB |
Output is correct |
79 |
Correct |
24 ms |
119644 KB |
Output is correct |
80 |
Correct |
28 ms |
131932 KB |
Output is correct |
81 |
Correct |
27 ms |
119648 KB |
Output is correct |
82 |
Correct |
25 ms |
123740 KB |
Output is correct |
83 |
Correct |
32 ms |
136028 KB |
Output is correct |
84 |
Correct |
26 ms |
125788 KB |
Output is correct |
85 |
Correct |
28 ms |
129884 KB |
Output is correct |
86 |
Correct |
28 ms |
129880 KB |
Output is correct |
87 |
Correct |
26 ms |
123736 KB |
Output is correct |
88 |
Correct |
33 ms |
136028 KB |
Output is correct |
89 |
Correct |
31 ms |
136020 KB |
Output is correct |
90 |
Correct |
26 ms |
125788 KB |
Output is correct |
91 |
Correct |
31 ms |
136028 KB |
Output is correct |
92 |
Correct |
31 ms |
135908 KB |
Output is correct |
93 |
Correct |
31 ms |
133980 KB |
Output is correct |