#include<cstdio> //传说中的差分约束
#include<cstring>
using namespace std;
inline int mymax(int a,int b) {return a>b?a:b;}
inline int mymin(int a,int b) {return a<b?a:b;}
struct node
{
int x,y,d,next;
}a[1110000];int len,last[1110000],n;
int maxx,minn;
void ins(int x,int y,int d)
{
len++;
a[len].x=x;a[len].y=y;a[len].d=d;
a[len].next=last[x];last[x]=len;
}
int d[110000],l[110000],head,tail;
bool v[110000];
void spfa(int st)
{
for(int i=minn;i<=maxx;i++) d[i]=-999999999;d[st]=0;
memset(v,false,sizeof(v));v[st]=true;
head=1;tail=2;l[1]=st;
while(head!=tail)
{
int x=l[head];
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(d[y]<d[x]+a[k].d)
{
d[y]=d[x]+a[k].d;
if(!v[y])
{
v[y]=true;
l[tail]=y;
tail++;
if(tail==109999) tail=1;
}
}
}
v[x]=false;
head++;
if(head==109999) head=1;
}
}
void clear()
{
len=0;
memset(last,0,sizeof(last));
minn=999999999;maxx=-999999999;
}
int main()
{
clear();
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
ins(a-1,b,c);
minn=mymin(minn,a-1);
maxx=mymax(maxx,b);
}
for(int i=minn;i<=maxx;i++)
{
ins(i,i+1,0);
ins(i+1,i,-1);
}
spfa(minn);
printf("%d\n",d[maxx]);
return 0;
}
一本通1509:【例 1】Intervals
最新推荐文章于 2024-08-21 11:22:17 发布