#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,L;
cin>>n>>L;
vector <int> a(n),b(n);
for(int i=0;i<n;i++)cin>>a[i];
map <int,int> dp[(1<<n)][n];
for(int i=0;i<n;i++){
cin>>b[i];
if(min(a[i],L-a[i])<=b[i])dp[(1<<i)][i][min(a[i],L-a[i])]=1;
}
for(int i=0;i<(1<<n);i++){
for(int j=0;j<n;j++){
if((i&(1<<j))){
int mask=i^(1<<j);
for(int l=0;l<n;l++){
if((mask&(1<<l))){
for(auto x : dp[mask][l]){
int mn=min(abs(a[j]-a[l]),L-max(a[j],a[l])+min(a[j],a[l]));
if(x.ff+mn<=b[j])dp[i][j][x.ff+mn]=max(dp[i][j][x.ff+mn],x.ss+1);
}
}
}
}
}
}
int mx=0;
for(int i=0;i<(1<<n);i++){
for(int j=0;j<n;j++){
for(auto x : dp[i][j])mx=max(mx,x.ss);
}
}
cout<<mx<<"\n";
}
/*
4 10
3 6 2 9
8 35
3 7 1 5 10 2 11 6
6 25
3 4 7 17 21 23
11 7 17 10 8 10
5 20
4 5 8 13 17
18 23 17 7 10
4 19
3 7 12 14
2 0 5 4
10 87
9 23 33 38 42 44 45 62 67 78
15 91 7 27 31 53 12 91 89 46
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
2652 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
4 ms |
2648 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
4956 KB |
Output is correct |
13 |
Correct |
4 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
46 ms |
14428 KB |
Output is correct |
17 |
Correct |
122 ms |
32824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
2652 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
4 ms |
2648 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
4956 KB |
Output is correct |
13 |
Correct |
4 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
46 ms |
14428 KB |
Output is correct |
17 |
Correct |
122 ms |
32824 KB |
Output is correct |
18 |
Correct |
16 ms |
11608 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
4 ms |
2596 KB |
Output is correct |
21 |
Correct |
17 ms |
11356 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1151 ms |
251764 KB |
Output is correct |
24 |
Correct |
7 ms |
5208 KB |
Output is correct |
25 |
Correct |
24 ms |
14172 KB |
Output is correct |
26 |
Correct |
16 ms |
11176 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
82 ms |
38820 KB |
Output is correct |
30 |
Correct |
52 ms |
28504 KB |
Output is correct |
31 |
Correct |
18 ms |
11096 KB |
Output is correct |
32 |
Correct |
7 ms |
5212 KB |
Output is correct |
33 |
Correct |
844 ms |
212444 KB |
Output is correct |
34 |
Correct |
506 ms |
149208 KB |
Output is correct |
35 |
Correct |
275 ms |
91212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
2652 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
4 ms |
2648 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
4956 KB |
Output is correct |
13 |
Correct |
4 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
46 ms |
14428 KB |
Output is correct |
17 |
Correct |
122 ms |
32824 KB |
Output is correct |
18 |
Runtime error |
646 ms |
1048576 KB |
Execution killed with signal 9 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
2652 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
4 ms |
2648 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
4956 KB |
Output is correct |
13 |
Correct |
4 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
46 ms |
14428 KB |
Output is correct |
17 |
Correct |
122 ms |
32824 KB |
Output is correct |
18 |
Correct |
16 ms |
11608 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
4 ms |
2596 KB |
Output is correct |
21 |
Correct |
17 ms |
11356 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1151 ms |
251764 KB |
Output is correct |
24 |
Correct |
7 ms |
5208 KB |
Output is correct |
25 |
Correct |
24 ms |
14172 KB |
Output is correct |
26 |
Correct |
16 ms |
11176 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
82 ms |
38820 KB |
Output is correct |
30 |
Correct |
52 ms |
28504 KB |
Output is correct |
31 |
Correct |
18 ms |
11096 KB |
Output is correct |
32 |
Correct |
7 ms |
5212 KB |
Output is correct |
33 |
Correct |
844 ms |
212444 KB |
Output is correct |
34 |
Correct |
506 ms |
149208 KB |
Output is correct |
35 |
Correct |
275 ms |
91212 KB |
Output is correct |
36 |
Runtime error |
646 ms |
1048576 KB |
Execution killed with signal 9 |
37 |
Halted |
0 ms |
0 KB |
- |