#include #include #include using namespace std; typedef long long ll; typedef pair P; int N,M; ll A,dp[100010] = {}; vector> v(100010); int main(){ cin >> N >> M >> A; assert(N<=100000 && M<=100000); int l,r; ll p; for(int i=0;i> l >> r >> p; assert(l<=r); v[r].push_back(P(l,p)); } ll ma = 0; for(int i=1;i<=N;i++){ dp[i] = ma-A; for(auto x:v[i]){ dp[i] = max(dp[i],dp[x.first-1]+x.second-(i==N? 0:A)); } ma = max(ma,dp[i]); } cout << ma << endl; }