#include #define rep(i,n) for(int i=0;i ; const int INF = 1e9; const int MOD = 1000000007; int main(){ ll n,m,a; cin >> n >> m >> a; vector> section(n+1); rep(i,m){ ll l,r,p; cin >> l >> r >> p; --l;--r; section[r+1].push_back(P(l,p)); } vector dp(n+1); ll ans = 0; dp[0] = 0; for(int i=1;i<=n;i++){ if(i==n){ dp[i] = 0; for(P s:section[i]){ dp[i] = max(dp[i],dp[s.first] + s.second); } ans = max(ans,dp[i]); continue; } dp[i] = -a; for(P s:section[i]){ dp[i] = max(dp[i],dp[s.first] + s.second - a); } ans = max(ans,dp[i]); //cout << dp[i] << endl; } cout << ans << endl; return 0; }