#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 405;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, l;
pii stm[MAXN];
int x[MAXN], t[MAXN];
int dp[MAXN][MAXN][205][2];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifdef Local
freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
#endif
cin>>n>>l;
for(int i = 0; i < n; i++) {
cin>>x[2*i];
x[2*i + 1] = x[2*i] - l;
}
stm[2*n] = {0, 0};
for(int i = 0; i < n; i++){
cin>>t[i];
stm[2*i] = {x[2*i], t[i]};
stm[2*i + 1] = {x[2*i + 1], t[i]};
}
sort(stm, stm + 2*n + 1);
int idx = 0;
for(int i = 0; i <= 2*n; i++){
if(stm[i] == make_pair(0, 0))
idx = i;
//cout<<stm[i].ff<<" "<<stm[i].ss<<endl;
}
memset(dp, 0x7f, sizeof(dp));
dp[idx][idx][0][0] = dp[idx][idx][0][1] = 0;
int ans = 0;
for(int i = 2; i <= n + 1; i++){
for(int j = idx - i + 1; j <= idx; j++){
dp[j][j + i - 1][0][0] = 2*stm[j + i - 1].ff - stm[j].ff;
dp[j][j + i - 1][0][1] = -2*stm[j].ff + stm[j + i - 1].ff;
for(int l = 1; l <= i; l++){
int &r = dp[j][j + i - 1][l][0];
r = min(r, dp[j + 1][j + i - 1][l][0] + stm[j + 1].ff - stm[j].ff);
r = min(r, dp[j + 1][j + i - 1][l][1] + stm[j + i - 1].ff - stm[j].ff);
if(stm[j + 1].ff - stm[j].ff + dp[j + 1][j + i - 1][l - 1][0] <= stm[j].ss){
r = min(r, stm[j + 1].ff - stm[j].ff + dp[j + 1][j + i - 1][l - 1][0]);
}
if(dp[j + 1][j + i - 1][l - 1][1] + stm[j + i - 1].ff - stm[j].ff <= stm[j].ss){
r = min(r, dp[j + 1][j + i - 1][l - 1][1] + stm[j + i - 1].ff - stm[j].ff);
}
int &rr = dp[j][j + i - 1][l][1];
rr = min(rr, dp[j][j + i - 2][l][0] + stm[j + i - 1].ff - stm[j].ff);
rr = min(rr, dp[j][j + i - 2][l][1] + stm[j + i - 1].ff - stm[j + i - 2].ff);
if(dp[j][j + i - 2][l - 1][0] + stm[j + i - 1].ff - stm[j].ff <= stm[i + j - 1].ss){
rr = min(rr, dp[j][j + i - 2][l - 1][0] + stm[j + i - 1].ff - stm[j].ff);
}
if(dp[j][j + i - 2][l - 1][1] + stm[j + i - 1].ff - stm[j + i - 2].ff <= stm[i + j - 1].ss){
rr = min(rr, dp[j][j + i - 2][l - 1][1] + stm[j + i - 1].ff - stm[j + i - 2].ff);
}
if(r <= 2e9 || rr <= 2e9){
ans = max(ans, l);
}
}
}
}
//cout<<dp[4][5][1][0]<<" "<<dp[4][5][1][1]<<endl;
cout<<ans<<endl;
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
263672 KB |
Output is correct |
2 |
Correct |
191 ms |
263544 KB |
Output is correct |
3 |
Correct |
163 ms |
263672 KB |
Output is correct |
4 |
Correct |
156 ms |
263544 KB |
Output is correct |
5 |
Correct |
155 ms |
263544 KB |
Output is correct |
6 |
Correct |
155 ms |
263544 KB |
Output is correct |
7 |
Correct |
159 ms |
263544 KB |
Output is correct |
8 |
Correct |
166 ms |
263548 KB |
Output is correct |
9 |
Correct |
152 ms |
263544 KB |
Output is correct |
10 |
Correct |
156 ms |
263672 KB |
Output is correct |
11 |
Correct |
159 ms |
263544 KB |
Output is correct |
12 |
Correct |
154 ms |
263544 KB |
Output is correct |
13 |
Correct |
155 ms |
263544 KB |
Output is correct |
14 |
Correct |
161 ms |
263544 KB |
Output is correct |
15 |
Correct |
157 ms |
263544 KB |
Output is correct |
16 |
Correct |
151 ms |
263544 KB |
Output is correct |
17 |
Correct |
160 ms |
263548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
263672 KB |
Output is correct |
2 |
Correct |
191 ms |
263544 KB |
Output is correct |
3 |
Correct |
163 ms |
263672 KB |
Output is correct |
4 |
Correct |
156 ms |
263544 KB |
Output is correct |
5 |
Correct |
155 ms |
263544 KB |
Output is correct |
6 |
Correct |
155 ms |
263544 KB |
Output is correct |
7 |
Correct |
159 ms |
263544 KB |
Output is correct |
8 |
Correct |
166 ms |
263548 KB |
Output is correct |
9 |
Correct |
152 ms |
263544 KB |
Output is correct |
10 |
Correct |
156 ms |
263672 KB |
Output is correct |
11 |
Correct |
159 ms |
263544 KB |
Output is correct |
12 |
Correct |
154 ms |
263544 KB |
Output is correct |
13 |
Correct |
155 ms |
263544 KB |
Output is correct |
14 |
Correct |
161 ms |
263544 KB |
Output is correct |
15 |
Correct |
157 ms |
263544 KB |
Output is correct |
16 |
Correct |
151 ms |
263544 KB |
Output is correct |
17 |
Correct |
160 ms |
263548 KB |
Output is correct |
18 |
Incorrect |
159 ms |
263544 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
263672 KB |
Output is correct |
2 |
Correct |
191 ms |
263544 KB |
Output is correct |
3 |
Correct |
163 ms |
263672 KB |
Output is correct |
4 |
Correct |
156 ms |
263544 KB |
Output is correct |
5 |
Correct |
155 ms |
263544 KB |
Output is correct |
6 |
Correct |
155 ms |
263544 KB |
Output is correct |
7 |
Correct |
159 ms |
263544 KB |
Output is correct |
8 |
Correct |
166 ms |
263548 KB |
Output is correct |
9 |
Correct |
152 ms |
263544 KB |
Output is correct |
10 |
Correct |
156 ms |
263672 KB |
Output is correct |
11 |
Correct |
159 ms |
263544 KB |
Output is correct |
12 |
Correct |
154 ms |
263544 KB |
Output is correct |
13 |
Correct |
155 ms |
263544 KB |
Output is correct |
14 |
Correct |
161 ms |
263544 KB |
Output is correct |
15 |
Correct |
157 ms |
263544 KB |
Output is correct |
16 |
Correct |
151 ms |
263544 KB |
Output is correct |
17 |
Correct |
160 ms |
263548 KB |
Output is correct |
18 |
Correct |
175 ms |
263548 KB |
Output is correct |
19 |
Correct |
163 ms |
263544 KB |
Output is correct |
20 |
Correct |
158 ms |
263544 KB |
Output is correct |
21 |
Correct |
171 ms |
263672 KB |
Output is correct |
22 |
Correct |
162 ms |
263544 KB |
Output is correct |
23 |
Correct |
164 ms |
263620 KB |
Output is correct |
24 |
Correct |
162 ms |
263592 KB |
Output is correct |
25 |
Correct |
155 ms |
263544 KB |
Output is correct |
26 |
Correct |
156 ms |
263544 KB |
Output is correct |
27 |
Correct |
157 ms |
263544 KB |
Output is correct |
28 |
Correct |
155 ms |
263544 KB |
Output is correct |
29 |
Correct |
163 ms |
263544 KB |
Output is correct |
30 |
Correct |
167 ms |
263488 KB |
Output is correct |
31 |
Correct |
160 ms |
263544 KB |
Output is correct |
32 |
Correct |
154 ms |
263544 KB |
Output is correct |
33 |
Correct |
159 ms |
263672 KB |
Output is correct |
34 |
Correct |
151 ms |
263544 KB |
Output is correct |
35 |
Correct |
180 ms |
263672 KB |
Output is correct |
36 |
Correct |
173 ms |
263524 KB |
Output is correct |
37 |
Correct |
184 ms |
263544 KB |
Output is correct |
38 |
Correct |
172 ms |
263672 KB |
Output is correct |
39 |
Correct |
173 ms |
263544 KB |
Output is correct |
40 |
Correct |
185 ms |
263624 KB |
Output is correct |
41 |
Correct |
200 ms |
263544 KB |
Output is correct |
42 |
Correct |
171 ms |
263544 KB |
Output is correct |
43 |
Correct |
180 ms |
263672 KB |
Output is correct |
44 |
Correct |
170 ms |
263544 KB |
Output is correct |
45 |
Correct |
174 ms |
263544 KB |
Output is correct |
46 |
Correct |
174 ms |
263544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
263672 KB |
Output is correct |
2 |
Correct |
191 ms |
263544 KB |
Output is correct |
3 |
Correct |
163 ms |
263672 KB |
Output is correct |
4 |
Correct |
156 ms |
263544 KB |
Output is correct |
5 |
Correct |
155 ms |
263544 KB |
Output is correct |
6 |
Correct |
155 ms |
263544 KB |
Output is correct |
7 |
Correct |
159 ms |
263544 KB |
Output is correct |
8 |
Correct |
166 ms |
263548 KB |
Output is correct |
9 |
Correct |
152 ms |
263544 KB |
Output is correct |
10 |
Correct |
156 ms |
263672 KB |
Output is correct |
11 |
Correct |
159 ms |
263544 KB |
Output is correct |
12 |
Correct |
154 ms |
263544 KB |
Output is correct |
13 |
Correct |
155 ms |
263544 KB |
Output is correct |
14 |
Correct |
161 ms |
263544 KB |
Output is correct |
15 |
Correct |
157 ms |
263544 KB |
Output is correct |
16 |
Correct |
151 ms |
263544 KB |
Output is correct |
17 |
Correct |
160 ms |
263548 KB |
Output is correct |
18 |
Incorrect |
159 ms |
263544 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |