#include using namespace std; #define FOR(i,s,t) for(int i = s; i < t; i++) using LL = long long; using VL = vector; int main() { int N, M, A; cin >> N >> M >> A; using PII = pair; vector>seg(N + 1); FOR(i, 0, M) { int L, R, V; cin >> L >> R >> V; seg[R].emplace_back(L, V); } const int USED = 1; const int SETED = 0; const LL LINF = 1e18; vector dp(N + 1, VL(2, -LINF)); auto setmax = [](LL &a, LL b) {a = max(a, b); }; dp[0][SETED] = 0; LL allmax = 0; FOR(R, 1, N + 1) { for (auto it : seg[R]) { int L = it.first; LL v = it.second + (R == N ? 0 : -A); setmax(dp[R][USED], dp[L - 1][SETED] + v); } setmax(dp[R][SETED], allmax - A); setmax(dp[R][SETED], dp[R][USED]); setmax(allmax, dp[R][SETED]); setmax(allmax, dp[R][USED]); } LL ans = 0; FOR(i, 0, N + 1) { setmax(ans, dp[i][USED]); setmax(ans, dp[i][SETED]); } cout << ans << endl; }