Dsc biggest dream is to have a game of their own (unlikely), you can create whimsy in their own virtual world out, assuming Dsc successful, created a an online game (the kind of small workshops ), now in order to save costs, Dsc decided to maintain their own server health, but there is always the lack of time.
S start from the assumption minutes, ending E min [S, E] Dsc this time is not the time, this time Dsc need someone to maintain the server, of course, is paid. There are n individual [S, E] this time free time (not necessarily all [S, E]) of the individual i ai, bi this time available, a total ci management fees.
Now please help Dsc told, he did not empty in time [S, E], have at least a minimum number of people spend a management server is needed every day, so if there is no program in the [S, E] time every day We have at least one output in the management server 1;
Input
first row of three integers n, S, E represents an n individuals are available, in the [S, E] Dsc not empty time
Then there are n lines, each line three integers ai, bi, ci denote the i-th individual available in [ai, bi] time, employ a total overhead required ci
1<=n<=1e5
0<=S<=E<=1e5
S<=ai<=bi<=E
1<=ci<=1e5
The Output
Dsc find someone to manage the required server in no time it takes a minimum of time, there is no program output -1
SampleInput
3 2 4
2 3 2
4 4 1
2 4 4
SampleOutput
3
meaning of the questions: to give you a given time interval and the time interval of the n sub-interval weighted asked consume minimal weight will point in the section completely covered
ideas: this title is a positive solution segment tree + dp, but I saw this question on the thought of the shortest path is covered but the shortest interval of time while this problem requires the point of the game I just thought of a given sub-interval an extension of the right end point (right), and the interval of point 1 of the right to build a side to side 0 (wrong), but this idea is the former, the latter on the WA, and even sample does not have to run , look behind the problem solution know the original map can also be built so orzzz, after an extension, and then we left point decrease one, to build a side for the right side of zero, so that it can traverse any n subintervals, popular point that It is that you can go back down the other side, specifically to see the code
#include <stdio.h>
#include <string.h>
#include <queue>
#include <deque>
#include <vector>
using namespace std;
typedef long long LL;///这题会爆int
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
struct edge
{
LL to,w;
edge() {}
edge(LL tt,LL ww):to(tt),w(ww) {};
};
vector<edge>a[maxn];
struct node
{
LL to,cost;
node() {}
node(LL tt,LL cc):to(tt),cost(cc) {};
friend bool operator < (const node &a,const node &b)
{
return a.cost > b.cost;
}
};
LL dist[maxn],vis[maxn];
int n,m,s,t;
void init()
{
for(int i=0; i<=n; i++)
{
a[i].clear();
}
}
LL dj(int s,int t)
{
for(int i=0; i<=n; i++)
{
dist[i]=inf;
vis[i]=0;
}
priority_queue<node>que;
que.push(node(s,0));
while(!que.empty())
{
node now=que.top();
que.pop();
if(!vis[now.to])
{
vis[now.to]=1;
dist[now.to]=now.cost;
for(int i=0; i<a[now.to].size(); i++)
{
LL t=a[now.to][i].to;
LL c=a[now.to][i].w;
if(!vis[t])
{
que.push(node(t,c+now.cost));
}
}
}
}
return dist[t]==inf ? -1:dist[t];
}
int main()
{
while(~scanf("%d%d%d",&n,&s,&t))
{
init();
for(int i=0; i<n; i++)
{
int x,y,v;
scanf("%d%d%d",&x,&y,&v);
a[x].push_back(edge(y+1,v));///给子区间向右伸长一位
}
for(int i=s+1;i<=n;i++)
{
a[i].push_back(edge(i-1,0));///建立反向边 使其可以遍历任意n个子区间 (有点像反悔)
}
LL ans=dj(s,t+1);
printf("%lld\n",ans);
}
return 0;
}