天梯赛-摘棉花
#include
#include
using namespace std;
int n, m, r, dp[1010] = {0};
struct item
{
int start, end, e;
bool operator<(const item &t) { return end < t.end; }
} a[1010];
int main(void)
{
cin >> n >> m >> r;
for (int i = 1; i <= m; i++)
cin >> a[i].start >> a[i].end >> a[i].e;
sort(a + 1, a + m + 1);
a[0].e = dp[0] = 0, a[0].end = a[0].start = -r;
for (int i = 1; i <= m; i++)
for (int j = 0; j < i; j++)
if (a[j].end + r <= a[i].start && dp[j] + a[i].e > dp[i])
dp[i] = dp[j] + a[i].e;
else if (dp[j] > dp[i])
dp[i] = dp[j];
cout << dp[m];
return 0;
}