poj 3616 Milking Time
#include<iostream> //dp
#include<algorithm>
using namespace std;
int dp[1005],n,m,r;
struct node
{
int s,e,eff;
bool operator<(const node& o)
{
return s<o.s||(s==o.s&&e<o.e);
}
}ans[1005];
int main()
{
int i,j;
cin>>n>>m>>r;
for(i=0;i<m;++i)
{
cin>>ans[i].s>>ans[i].e>>ans[i].eff;
ans[i].e+=r;
}
sort(ans,ans+m);
for(i=0;i<m;++i)
{
dp[i]=ans[i].eff;
for(j=0;j<i;++j)
if(ans[j].e<=ans[i].s)
dp[i]=max(dp[i],dp[j]+ans[i].eff);
}
cout<<*max_element(dp,dp+m)<<endl;
return 0;
}