#include #include #include using namespace std; void getint(int &x) { int ch = x = 0; while (!isdigit(ch = getchar())) ; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; } const int M = 1e3 + 5; struct Int { int s, e, x; } Ints[M]; bool operator<(const Int &lhs, const Int &rhs) { return lhs.s < rhs.s; } int f[M]; int main() { int n, m, r; getint(n), getint(m), getint(r); for (int i = 0; i < m; i++) getint(Ints[i].s), getint(Ints[i].e), getint(Ints[i].x), Ints[i].e += r; sort(Ints, Ints + m); for (int i = 0; i < m; i++) { f[i] = Ints[i].e; for (int j = 0; j < i; j++) if (Ints[j].e <= Ints[i].s) f[i] = max(f[i], f[j] + Ints[i].x); } printf("%d", *max_element(f, f + m)); return 0; }