定义:dp[i] := 在已排好序的list的第 i 次John可从Bessie获取的最大牛奶量
dp[i] = max(dp[i], myNode[i].myvalue + dp[j]);
// 条件是: myNode[j].myend + R <= myNode[i].mystart (两重循环解决)
// [4/4/2014 Sjm]
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX_M = 1000, MAX_N = 1000001;
int N, M, R;
struct node {
int mystart, myend, myvalue;
};
bool Cmp(const node n1, const node n2) {
if (n1.mystart == n2.mystart) return n1.myend < n2.myend;
else return n1.mystart < n2.mystart;
}
node myNode[MAX_M];
int dp[MAX_M];
int Solve()
{
for (int i = 0; i < M; i++)
for (int j = 0; j < i; j++){
if (myNode[j].myend + R <= myNode[i].mystart){
dp[i] = max(dp[i], myNode[i].myvalue + dp[j]);
}
}
int ans = 0;
for (int i = 0; i < M; i++)
ans = max(ans, dp[i]);
return ans;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
scanf("%d%d%d", &N, &M, &R);
for (int i = 0; i < M; i++) {
scanf("%d%d%d", &myNode[i].mystart, &myNode[i].myend, &myNode[i].myvalue);
}
sort(myNode, myNode + M, Cmp);
for (int i = 0; i < M; i++)
dp[i] = myNode[i].myvalue;
printf("%d\n", Solve());
return 0;
}