#define _GLIBCXX_DEBUG #include"bits/stdc++.h" using namespace std; //loops #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define OneToN(i,n) for(ll i=1;i<(ll)(n+1);i++) #define ZeroToN(i,n) for(ll i=0;i<(ll)(n+1);i++) #define AToB(i,a,b) for(ll i=a;i<(ll)(b+1);i++) #define FOR(i,a,b) for(ll i=(a);i<=(b);i++) #define FORD(i,a,b) for(ll i=(a);i>=(b);i--) //bitsearch #define BITSEARCH(bit, n) for (int bit = 0; bit < (1< std::vector slice(std::vector const &v, int m, int n) { auto first = v.cbegin() + m; auto last = v.cbegin() + n + 1; std::vector vec(first, last); return vec; } //v need to be sorted #define remove_unique(v) v.erase(unique(ALL(v)), v.end()) //comparision template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } //pair #define fir first #define sec second #define mp make_pair //types #define ll long long #define vec vector #define cord2d pair #define intP pair //UNCOMMENT WHEN NEEDED //#define int ll //input template T get(){ T s; cin >> s; return(s);} #define gi get() #define gs get() #define gll get() template vector getv(int n) { vec v(n); REP(i, n) cin >> v[i]; return v; } #define gim(n) getv(n) #define gsm(n) getv(n) #define gllm(n) getv(n) //output void print(int a){ cout << a << endl; } void print(long long a){ cout << a << endl; } void print(string a){ cout << a << endl; } void print(char a){ cout << a << endl; } void print(double a){ cout << a << endl; } void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; } template ostream &operator<<(ostream &o,const vector&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")< void print(vec v){ cout << v << endl; } template void print2dVec(vec> v2d){for(vec v: v2d) {print(v);}} void YesNo1(bool i = true){ return print(i?"Yes":"No"); } void YESNO2(bool i = true){ return print(i?"YES":"NO"); } //debug output #define var_name(var) #var template void debug(T &var, int nest = 0, string before = "") { cout << string(" ", nest) << before; print(var); } //name replacement #define y0 y0__ #define y1 y1__ #define j0 j0__ #define j1 j1__ //bool lambdas #define lamb(exp) [](auto i){return exp;} #define isEven [](int i){return i % 2 == 0;} #define isOdd [](int i){return i % 2 != 0;} //constants const ll INF = 1e18; const int MOD = 1000000007; //maths int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; } ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; } //////////////////// void Main() { //code here int n = gi, k = gi; vec ups = gim(n); vec downs = gim(n); assert(1 <= n && n <= pow(10,5)); assert(0 <= n && k <= pow(10,8)); REP(i,n) { assert(0 <= ups[i] && ups[i] <= pow(10,8)); assert(0 <= downs[i] && downs[i] <= pow(10,8)); } if (n == 1) { print(0); return; } vec dp(n, INF); dp[0] = 0; REP(i,n-2) { chmin(dp[i+2], dp[i] + ups[i] + downs[i+2] + k); chmin(dp[i+1], dp[i] + ups[i] + downs[i+1]); } chmin(dp[n-1], dp[n-2] + ups[n-2] + downs[n-1]); //print(dp); print(max(dp[n-2], dp[n-1])); } signed main() { cin.tie(0); ios::sync_with_stdio(false); Main(); }