Language: C++

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cmath>
#include <map>
#include <cstdlib>
#include <string>
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;

long long fastpow(int a, int b, int MOD)
{
    long long x=1,y=a; 
    while(b > 0)
    {
        if(b%2 == 1)
        {
            x=(x*y) % MOD;
        }
        y = (y*y) % MOD;
        b /= 2;
    }
    return x;
}

long long InverseEuler(int n, int MOD)
{
    return fastpow(n,MOD-2,MOD);
}
 
long long f[300000];
bool init;
long long C(int n, int r, int MOD)
{
    if (!init){
        init=1;
        f[0]=1;
        for (int i=1; i<300000;i++)
            f[i]= (f[i-1]*i) % MOD;
        
    }
    return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}

bool ada[999];

map<long long,int> ans;


void coba(vector<long long> state) {
    if (state.size() == 1) ans[state[0]]++;
    else {
        int X = state.size();
        for (int i=0;i<X;i++)
            for (int j=0;j<X;j++){
                if (i==j) continue;
                
                vector<long long> tmp;
                for (int k=0;k<X;k++){
                    if (k == i || k == j) continue;
                    tmp.push_back(state[k]);
                }
                
                tmp.push_back(state[j] + (state[j] - state[i]));   
                coba(tmp);
            }
    }
}
long long l[3001],t[3001];
long long dp[3001][3001][2];
   int N;
   long long L;

long long solve(int kir, int kan, int mana) {
  if (dp[kir][kan][mana]!=-1) return dp[kir][kan][mana];
  if (kir == kan) {
    if (mana == 0) {
      dp[kir][kan][mana] = L - l[kir] + L;
      return  dp[kir][kan][mana];
    }  else {
      dp[kir][kan][mana] = l[kir];
      return  dp[kir][kan][mana]; 
    }
  }
  if (mana == 0 ) { //kanan
    dp[kir][kan][mana] = min( solve(kir + 1, kan, 0) + (l[kir+1] - l[kir]) + (t[kir+1]/(2*L))*(2*L) + 2*L, 
                              solve(kir + 1, kan, 1) + (l[kan] - l[kir]) + ((t[kan] - 2*(L - l[kan]) + 2*L - 1)/(2*L))*(2*L) + 2*(L - l[kan]) );

  } else {
    dp[kir][kan][mana] = min( solve(kir, kan - 1, 0) + abs(l[kir] - l[kan]) + ( (t[kir] - 2*l[kir] + 2*L - 1) /(2*L))*(2*L) + 2*l[kir], 
                              solve(kir, kan - 1, 1) + abs(l[kan] - l[kan - 1]) + (t[kan-1]/(2*L))*(2*L) + 2*L );

  
  }
  return dp[kir][kan][mana];
}

int main(){
   std::ios::sync_with_stdio(false); 

   cin>>N>>L;
   l[0] = 0;
   t[0] = 0;
   for (int i=1;i<=N;i++) cin>>l[i];
  for (int i=1;i<=N;i++) cin>>t[i];

   memset(dp, -1, sizeof(dp));

   cout<<solve(0, N, 0)<<endl;

/*
   for (int i=0;i<=N;i++)
    for (int j=i;j<=N;j++)
      for (int k=0;k<2;k++){
      cout<<i<<" : "<<j<<" : "<<k<<"  = "<<dp[i][j][k]<<endl;
    }*/
}


Compiler output:
a.cc: In function 'int main()':
a.cc:117:4: error: 'memset' was not declared in this scope
  117 |    memset(dp, -1, sizeof(dp));
      |    ^~~~~~
a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    8 | #include <cstdlib>
  +++ |+#include <cstring>
    9 | #include <string>