1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 500+100
14 #define maxm 1000+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 using namespace std;
19 inline int read()
20 {
21 int x=0,f=1;char ch=getchar();
22 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
23 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
24 return x*f;
25 }
26 ll ans,f[maxm];
27 struct rec{int s,e,p;}a[maxm];
28 int n,m,r;
29 inline bool cmp(rec a,rec b)
30 {
31 return a.s<b.s;
32 }
33 int main()
34 {
35 freopen("input.txt","r",stdin);
36 freopen("output.txt","w",stdout);
37 n=read();m=read();r=read();
38 for(int i=1;i<=m;i++)a[i].s=read(),a[i].e=read()+r,a[i].p=read();
39 sort(a+1,a+m+1,cmp);
40 for(int i=1;i<=m;i++)
41 {
42 f[i]=a[i].p;
43 for(int j=1;j<=i-1;j++)
44 if(a[j].e<=a[i].s)f[i]=max(f[i],f[j]+a[i].p);
45 ans=max(ans,f[i]);
46 }
47 printf("%lld\n",ans);
48 return 0;
49 }