#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define f first
#define s second
const long long inf = 1000000000000000007;
const int maxn = 202;
int n, m;
pi a[maxn];
long long dp[maxn][maxn][maxn][2];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i].f;
for(int i = 1; i <= n; i++) cin >> a[i].s;
a[n + 1].f = m;
sort(a + 1, a + n + 1);
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
for(int k = n + 1; k > j; k--) dp[i][j][k][0] = dp[i][j][k][1] = inf;
int ret = 0;
dp[0][0][n + 1][0] = dp[0][0][n + 1][1] = 0;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
for(int k = n + 1; k > j; k--){
long long x;
bool t0 = 0, t1 = 0;
if(dp[i][j][k][0] != inf){
ret = i;
x = dp[i][j][k][0] + a[j + 1].f - a[j].f;
if(x <= dp[i][j + 1][k][0]){
dp[i][j + 1][k][0] = x;
t0 = 1;
}
x = dp[i][j][k][0] + a[j].f + m - a[k - 1].f;
if(x <= dp[i][j][k - 1][1]){
dp[i][j][k - 1][1] = x;
t1 = 1;
}
}
if(dp[i][j][k][1] != inf){
ret = i;
x = dp[i][j][k][1] + a[k].f - a[k - 1].f;
if(x <= dp[i][j][k - 1][1]){
dp[i][j][k - 1][1] = x;
t1 = 1;
}
x = dp[i][j][k][1] + a[j + 1].f + m - a[k].f;
if(x <= dp[i][j + 1][k][0]){
dp[i][j + 1][k][0] = x;
t0 = 1;
}
}
if(t0 && dp[i][j + 1][k][0] <= a[j + 1].s) dp[i + 1][j + 1][k][0] = dp[i][j + 1][k][0];
if(t1 && dp[i][j][k - 1][1] <= a[k - 1].s) dp[i + 1][j][k - 1][1] = dp[i][j][k - 1][1];
}
cout << ret << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |