#include using namespace std; void chmax(int64_t& a, int64_t b){ a = max(a, b); } int main(){ int N, M, A; cin >> N >> M >> A; vector> R2LP[100001]; for(int i=0; i> l >> r >> p; R2LP[r].push_back({l, p}); } const int64_t INF = 1e18; vector dp(N+1, -INF); dp[0] = 0; int64_t mx = 0; for(int i=1; i<=N; i++){ for(auto& p : R2LP[i]){ int l = p.first, pt = p.second; int64_t cost = (i == N ? 0 : A); chmax(dp[i], dp[l-1] - cost + pt); } chmax(dp[i], mx - A); chmax(mx, dp[i]); } int64_t ans = *max_element(dp.begin(), dp.end()); cout << ans << endl; return 0; }