const INF: isize = 1isize << 60; fn main() { let mut nma = String::new(); std::io::stdin().read_line(&mut nma).ok(); let nma: Vec = nma.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nma[0]; let m = nma[1]; let a = nma[2] as isize; let mut lines = (0..m).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0]-1, temp[1], temp[2] as isize) }) .collect::>(); let mut dp = vec![vec![-INF; 2]; n+1]; for i in 0..=n { dp[i][0] = 0; } dp[0][1] = 0; let mut lidx = 0usize; for &(l, r, p) in lines.iter() { while lidx < l { dp[lidx+1][0] = dp[lidx+1][0].max(dp[lidx][0]).max(dp[lidx][1]); lidx += 1; } let leftcost = if l == 0 { 0 } else { a }; let rightcost = if r == n { 0 } else { a }; dp[r][1] = dp[r][1].max(dp[l][0] - leftcost - rightcost + p).max(dp[l][1] - rightcost + p); } println!("{}", dp.iter().map(|v| v.iter().max().unwrap()).max().unwrap()); }