# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203332 | staniewzki | Collecting Stamps 3 (JOI20_ho_t3) | C++14 | 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;
ostream& operator<<(ostream &out, string str) {
for(char c : str) out << c;
return out;
}
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
return out << "(" << p.first << ", " << p.second << ")";
}
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
out << "{";
for(auto it = a.begin(); it != a.end(); it = next(it))
out << (it != a.begin() ? ", " : "") << *it;
return out << "}";
}
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
cerr << a << ", ";
dump(x...);
}
#ifdef DEBUG
# define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
# define debug(...) false
#endif
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
template<class T> int size(T && a) { return a.size(); }
using LL = long long;
using PII = pair<LL, LL>;
template<class T> auto create(T x) { return x; }
int create(int n) { return n; }
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, LL(1e9 + 1));
vector<int> d(n + 2);
FOR(i, 1, n) d[i] = x[i - 1];
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;
FOR(l, 0, n) FOR(r, 0, n) {
if(l + r > n) break;
FOR(k, 0, n) {
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";
}