func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = (int)15e4 + 10, M = 310;   int n, m, d;   long long a[N], b[N], t[N], tmp[N], dp[2][N];   inline void f(int j) {     long long k = 1ll * (t[j] - t[j - 1]) * d;     int r = j % 2;     deque<int> deq;     for (int i = 0; i < n; i++) {       while (deq.size() && dp[!r][deq.back()] <= dp[!r][i]) deq.pop_back();       deq.push_back(i);       while (deq.front() < i - k) deq.pop_front();       tmp[i] = dp[!r][deq.front()];     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> d;     for (int i = 0; i < m; i++) {       cin >> a[i] >> b[i] >> t[i];       a[i]--;     }     for (int i = 0; i < n; i++) dp[0][i] = b[0] - abs(a[0] - i);     for (int j = 1; j < m; j++) {       int r = j % 2;       f(j);       for (int i = 0; i < n; i++) dp[r][i] = tmp[i];       reverse(dp[!r], dp[!r] + n);       f(j);       for (int i = 0; i < n; i++) dp[r][i] = max(dp[r][i], tmp[n - 1 - i]);       for (int i = 0; i < n; i++) dp[r][i] += b[j] - abs(a[j] - i);     }     m--;     cout << *max_element(dp[m % 2], dp[m % 2] + n);     return 0;   }   