#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
using namespace std;
ll n,m,k,i,j,ans,a[25],t[25],d[25][25][25][25];
ll check(int l, int r, int pos, int cnt){
if(cnt==0)return 1e14;
if(l>r)return -1e14;
if(d[l][r][pos][cnt]!=-1)return d[l][r][pos][cnt];
ll ans=-1e14;
int lc;
if(pos==0) lc=l-1;
else lc=r+1;
ans=max(ans,check(l+1,r,0,cnt)-(min(abs(a[l]-a[lc]),m-abs(a[l]-a[lc]))));
ans=max(ans,check(l,r-1,1,cnt)-(min(abs(a[r]-a[lc]),m-abs(a[r]-a[lc]))));
ans=max(ans,min(t[l],check(l+1,r,0,cnt-1))-(min(abs(a[l]-a[lc]),m-abs(a[l]-a[lc]))));
ans=max(ans,min(t[r],check(l,r-1,1,cnt-1))-(min(abs(a[r]-a[lc]),m-abs(a[r]-a[lc]))));
d[l][r][pos][cnt]=ans;
return ans;
}
int main() {
cin>>n>>m;
for(k=0; k<n; k++)cin>>a[k];
for(k=0; k<n; k++)cin>>t[k];
memset(d,-1,sizeof d);
ll fans=0;
for(k=0; k<=n; k++) {
if(check(0,n-1,1,k)>=0)fans=k;}
cout<<fans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Correct |
1 ms |
3420 KB |
Output is correct |
9 |
Correct |
1 ms |
3420 KB |
Output is correct |
10 |
Correct |
1 ms |
3420 KB |
Output is correct |
11 |
Correct |
1 ms |
3420 KB |
Output is correct |
12 |
Correct |
2 ms |
3416 KB |
Output is correct |
13 |
Correct |
2 ms |
3416 KB |
Output is correct |
14 |
Correct |
1 ms |
3420 KB |
Output is correct |
15 |
Correct |
1 ms |
3420 KB |
Output is correct |
16 |
Correct |
1 ms |
3420 KB |
Output is correct |
17 |
Correct |
1 ms |
3340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Correct |
1 ms |
3420 KB |
Output is correct |
9 |
Correct |
1 ms |
3420 KB |
Output is correct |
10 |
Correct |
1 ms |
3420 KB |
Output is correct |
11 |
Correct |
1 ms |
3420 KB |
Output is correct |
12 |
Correct |
2 ms |
3416 KB |
Output is correct |
13 |
Correct |
2 ms |
3416 KB |
Output is correct |
14 |
Correct |
1 ms |
3420 KB |
Output is correct |
15 |
Correct |
1 ms |
3420 KB |
Output is correct |
16 |
Correct |
1 ms |
3420 KB |
Output is correct |
17 |
Correct |
1 ms |
3340 KB |
Output is correct |
18 |
Correct |
1 ms |
3416 KB |
Output is correct |
19 |
Correct |
1 ms |
3420 KB |
Output is correct |
20 |
Correct |
1 ms |
3420 KB |
Output is correct |
21 |
Correct |
2 ms |
3384 KB |
Output is correct |
22 |
Correct |
1 ms |
3420 KB |
Output is correct |
23 |
Correct |
1 ms |
3260 KB |
Output is correct |
24 |
Correct |
1 ms |
3416 KB |
Output is correct |
25 |
Correct |
1 ms |
3420 KB |
Output is correct |
26 |
Correct |
1 ms |
3420 KB |
Output is correct |
27 |
Correct |
2 ms |
3420 KB |
Output is correct |
28 |
Correct |
2 ms |
3416 KB |
Output is correct |
29 |
Correct |
1 ms |
3420 KB |
Output is correct |
30 |
Correct |
1 ms |
3256 KB |
Output is correct |
31 |
Correct |
1 ms |
3420 KB |
Output is correct |
32 |
Correct |
1 ms |
3456 KB |
Output is correct |
33 |
Correct |
1 ms |
3420 KB |
Output is correct |
34 |
Correct |
1 ms |
3420 KB |
Output is correct |
35 |
Correct |
1 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Correct |
1 ms |
3420 KB |
Output is correct |
9 |
Correct |
1 ms |
3420 KB |
Output is correct |
10 |
Correct |
1 ms |
3420 KB |
Output is correct |
11 |
Correct |
1 ms |
3420 KB |
Output is correct |
12 |
Correct |
2 ms |
3416 KB |
Output is correct |
13 |
Correct |
2 ms |
3416 KB |
Output is correct |
14 |
Correct |
1 ms |
3420 KB |
Output is correct |
15 |
Correct |
1 ms |
3420 KB |
Output is correct |
16 |
Correct |
1 ms |
3420 KB |
Output is correct |
17 |
Correct |
1 ms |
3340 KB |
Output is correct |
18 |
Runtime error |
5 ms |
6748 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Correct |
1 ms |
3420 KB |
Output is correct |
9 |
Correct |
1 ms |
3420 KB |
Output is correct |
10 |
Correct |
1 ms |
3420 KB |
Output is correct |
11 |
Correct |
1 ms |
3420 KB |
Output is correct |
12 |
Correct |
2 ms |
3416 KB |
Output is correct |
13 |
Correct |
2 ms |
3416 KB |
Output is correct |
14 |
Correct |
1 ms |
3420 KB |
Output is correct |
15 |
Correct |
1 ms |
3420 KB |
Output is correct |
16 |
Correct |
1 ms |
3420 KB |
Output is correct |
17 |
Correct |
1 ms |
3340 KB |
Output is correct |
18 |
Correct |
1 ms |
3416 KB |
Output is correct |
19 |
Correct |
1 ms |
3420 KB |
Output is correct |
20 |
Correct |
1 ms |
3420 KB |
Output is correct |
21 |
Correct |
2 ms |
3384 KB |
Output is correct |
22 |
Correct |
1 ms |
3420 KB |
Output is correct |
23 |
Correct |
1 ms |
3260 KB |
Output is correct |
24 |
Correct |
1 ms |
3416 KB |
Output is correct |
25 |
Correct |
1 ms |
3420 KB |
Output is correct |
26 |
Correct |
1 ms |
3420 KB |
Output is correct |
27 |
Correct |
2 ms |
3420 KB |
Output is correct |
28 |
Correct |
2 ms |
3416 KB |
Output is correct |
29 |
Correct |
1 ms |
3420 KB |
Output is correct |
30 |
Correct |
1 ms |
3256 KB |
Output is correct |
31 |
Correct |
1 ms |
3420 KB |
Output is correct |
32 |
Correct |
1 ms |
3456 KB |
Output is correct |
33 |
Correct |
1 ms |
3420 KB |
Output is correct |
34 |
Correct |
1 ms |
3420 KB |
Output is correct |
35 |
Correct |
1 ms |
3420 KB |
Output is correct |
36 |
Runtime error |
5 ms |
6748 KB |
Execution killed with signal 11 |
37 |
Halted |
0 ms |
0 KB |
- |