#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; struct Node { int id; ll t; Node(int id = -1, ll t = -1) { this->id = id; this->t = t; } bool operator>(const Node &n) const { return t > n.t; } }; int main() { ll N, K; cin >> N >> K; vector A(N); vector B(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } for (int i = 0; i < N; ++i) { cin >> B[i]; } priority_queue , greater> pque; vector time(N, LLONG_MAX); ll ans = 0; time[0] = 0; if (N >= 2) { pque.push(Node(1, A[0] + B[1])); } if (N >= 3) { pque.push(Node(2, A[0] + B[2] + K)); } while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (time[node.id] <= node.t) continue; time[node.id] = node.t; ans = max(ans, node.t); if (node.id + 1 < N) { pque.push(Node(node.id + 1, node.t + A[node.id] + B[node.id + 1])); } if (node.id + 2 < N) { pque.push(Node(node.id + 2, node.t + A[node.id] + B[node.id + 2] + K)); } } cout << ans << endl; return 0; }