Language: C++

// Code by H~$~C
#include <bits/stdc++.h>
using namespace std;

static const int Maxn = 100005;

#define int long long

int n;
long long T, E;
long long a[Maxn];
long long dp[Maxn];
// dp[i] = min { dp[j] + a[i] - a[j] + max(T, 2 * (a[i] - a[j + 1]) }
// dpt[i] = min { dpt[j] + max(T, 2 * (a[i] - a[j + 1])) }
// dp[i] = dpt[i] + a[i]
// Ans = dp[n] + (E - a[n]) = dpt[n] + E

namespace sgt1 {
  #define ls (p * 2 + 1)
  #define rs (p * 2 + 2)
  #define mid (l + r >> 1)
  long long tr[Maxn << 2];
  inline void init() {
    memset(tr, 0x3f, sizeof(tr));
  }
  inline void pushup(int p) {
    tr[p] = min(tr[ls], tr[rs]);
  }
  void modify(int p, int l, int r, int pos, long long val) {
    if (l == r) {
      tr[p] = min(tr[p], val);
      return ;
    }
    if (pos <= mid) {
      modify(ls, l, mid, pos, val);
    }
    else {
      modify(rs, mid + 1, r, pos, val);
    }
  }
  long long query(int p, int l, int r, int L, int R) {
    if (L > r || l > R) return 1e18;
    if (L <= l && r <= R) {
      return tr[p];
    }
    long long left = query(ls, l, mid, L, R);
    long long right = query(rs, mid + 1, r, L, R);
    return min(left, right);
  }
  #undef ls
  #undef rs
  #undef mid
}
namespace sgt2 {
  #define ls (p * 2 + 1)
  #define rs (p * 2 + 2)
  #define mid (l + r >> 1)
  long long tr[Maxn << 2];
  inline void init() {
    memset(tr, 0x3f, sizeof(tr));
  }
  inline void pushup(int p) {
    tr[p] = min(tr[ls], tr[rs]);
  }
  void modify(int p, int l, int r, int pos, long long val) {
    if (l == r) {
      tr[p] = min(tr[p], val);
      return ;
    }
    if (pos <= mid) {
      modify(ls, l, mid, pos, val);
    }
    else {
      modify(rs, mid + 1, r, pos, val);
    }
  }
  long long query(int p, int l, int r, int L, int R) {
    if (L > r || l > R) return 1e18;
    if (L <= l && r <= R) {
      return tr[p];
    }
    long long left = query(ls, l, mid, L, R);
    long long right = query(rs, mid + 1, r, L, R);
    return min(left, right);
  }
  #undef ls
  #undef rs
  #undef mid
}

signed main() {
  scanf("%lld%lld%lld", &n, &E, &T);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", a + i);
  }
  
  memset(dp, 63, sizeof(dp));
  dp[0] = 0;
  sgt1::init();
  sgt2::init();
  sgt1::modify(0, 0, n, 0, dp[0]);
  sgt2::modify(0, 0, n, 0, dp[0] - 2 * a[1]);
  for (int i = 1; i <= n; ++i) {
    int low = 0, high = i;
    while (high - low > 1) {
      int mid = low + high >> 1;
      if ((a[i] - a[mid]) * 2 > T) L = mid;
      else R = mid;
    }
    int pos = L;
    if (pos < i) {
      dp[i] = min(dp[i], sgt1::query(0, 0, n, pos, i - 1) + T);
    }
    if (pos > 0) {
      dp[i] = min(dp[i], sgt2::query(0, 0, n, 0, pos - 1) + 2 * a[i]);
    }
    sgt1::modify(0, 0, n, i, dp[i]);
    sgt2::modify(0, 0, n, i, dp[i] - 2 * a[i + 1]);
  }
  printf("%lld\n", dp[n] + E);
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:107:36: error: 'L' was not declared in this scope
  107 |       if ((a[i] - a[mid]) * 2 > T) L = mid;
      |                                    ^
a.cc:108:12: error: 'R' was not declared in this scope
  108 |       else R = mid;
      |            ^
a.cc:110:15: error: 'L' was not declared in this scope
  110 |     int pos = L;
      |               ^