# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203336 | staniewzki | Collecting Stamps 3 (JOI20_ho_t3) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> auto create(T x) { return x; }
template<class... Ts> auto create(int n, Ts... x) {
return vector(n, create(x...));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, len;
cin >> n >> len;
vector<int> x(n), t(n);
REP(i, n) cin >> x[i];
REP(i, n) cin >> t[i];
auto dp = create(n + 1, n + 1, n + 1, 2, long long(1e9 + 1));
vector<int> d(n + 2);
REP(i, n) d[i + 1] = x[i];
d[n + 1] = len;
auto left = [&](int a, int b) { return d[b] - d[a]; };
auto right = [&](int a, int b) { return d[n + 1 - a] - d[n + 1 - b]; };
dp[0][0][0][0] = 0;
dp[0][0][0][1] = 0;
int ans = 0;
REP(l, n + 1) REP(r, n + 1) {
if(l + r > n) break;
REP(k, n + 1) {
if(l) {
dp[l][r][k][0] = min(dp[l][r][k][0], dp[l - 1][r][k][0] + left(l - 1, l));
dp[l][r][k][0] = min(dp[l][r][k][0], dp[l - 1][r][k][1] + left(0, l) + right(0, r));
}
if(r) {
dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r - 1][k][1] + right(r - 1, r));
dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r - 1][k][0] + left(0, l) + right(0, r));
}
}
for(int k = n; k >= 1; k--) {
if(l && dp[l][r][k - 1][0] <= t[l - 1]) {
dp[l][r][k][0] = dp[l][r][k - 1][0];
ans = max(ans, k);
}
if(r && dp[l][r][k - 1][1] <= t[n - r]) {
dp[l][r][k][1] = dp[l][r][k - 1][1];
ans = max(ans, k);
}
}
}
cout << ans << "\n";
}