728x90
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <algorithm>
struct s{
int st;
int en;
int v;
};
bool comp(const s &a,const s &b){
return a.en<b.en;
}
int main()
{
int n,m,r;
std::cin>>n>>m>>r;
std::vector<s> infos(m);
std::vector<int> res(m);
for(int i=0;i<m;i++){
std::cin>>infos[i].st>>infos[i].en>>infos[i].v;
}
std::sort(infos.begin(),infos.end(),comp);
int ans=INT_MIN;
for(int i=0;i<infos.size();i++){
res[i]=infos[i].v;
int max_v = res[i];
for(int j=0;j<i;j++){
if(infos[j].en+r<=infos[i].st){
max_v = std::max(max_v,infos[i].v+res[j]);
}
}
res[i]=max_v;
}
for(auto &p:res){
ans = std::max(ans,p);
}
std::cout<<ans;
return 0;
}