//题意:M个小时时间间隔内获取牛奶 再接下来有N个时间,但是每个时间段之间必须有R个休息时间
//每个时间段有个开始时间结束时间和生成牛奶数量,求出最大生成牛奶的可能数量
//思路:dp[i]表示用i为末尾时间的,生产的最大的牛奶数目类似最长子序列问题
//每个时间段有个开始时间结束时间和生成牛奶数量,求出最大生成牛奶的可能数量
//思路:dp[i]表示用i为末尾时间的,生产的最大的牛奶数目类似最长子序列问题
//196K 16MS
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct mike_product{
int start_time;
int end_time;
int nproduce;
};
int cmp(const mike_product&lhs,const mike_product&rhs){
return lhs.start_time<rhs.start_time;
}
int main(){
int N,M,R;
scanf("%d %d %d",&N,&M,&R);
vector<mike_product>vproduct;
vproduct.resize(M+1);
for(int i=1;i<=M;++i)
scanf("%d %d %d",&vproduct[i].start_time,
&vproduct[i].end_time,&vproduct[i].nproduce);
sort(vproduct.begin(),vproduct.end(),cmp);
vector<int>dp;
dp.resize(M+1);
for (int i=1;i<=M;++i)
{
dp[i] = vproduct[i].nproduce;
}
int ans = 0;
for (int i=1;i<=M;++i)
{
for (int j=i;j>=1;--j)
{
if (vproduct[i].start_time>=(vproduct[j].end_time+R))
{
dp[i] = max(dp[i],dp[j]+vproduct[i].nproduce);
}
ans = max(dp[i],ans);
}
}
printf("%d\n",ans);
return 0;
}