1 #include<cstdio>
2
3 #include<cstdlib>
4
5 #include<cmath>
6
7 #include<cstring>
8
9 #include<algorithm>
10
11 #include<iostream>
12
13 #include<vector>
14
15 #include<map>
16
17 #include<set>
18
19 #include<queue>
20
21 #include<string>
22
23 #define inf 100000000000
24
25 #define maxn 80000+2000
26
27 #define maxm 500+100
28
29 #define eps 1e-10
30
31 #define ll long long
32
33 #define pa pair<int,int>
34
35 #define for0(i,n) for(int i=0;i<=(n);i++)
36
37 #define for1(i,n) for(int i=1;i<=(n);i++)
38
39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
40
41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
42
43 #define mod 1000000007
44
45 using namespace std;
46
47 inline int read()
48
49 {
50
51 int x=0,f=1;char ch=getchar();
52
53 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
54
55 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
56
57 return x*f;
58
59 }
60
61 struct rec{int l,r;ll w;}a[maxn];
62
63 struct seg{int l,r;ll mi,tag;}t[4*maxn];
64
65 int n,x,y;
66
67 inline bool cmp(rec a,rec b)
68
69 {
70
71 return a.l<b.l||(a.l==b.l&&a.r<b.r);
72
73 }
74
75 inline void pushup(int k)
76
77 {
78
79 t[k].mi=min(t[k<<1].mi,t[k<<1|1].mi);
80
81 }
82
83 inline void update(int k,ll z)
84
85 {
86
87 t[k].mi=min(t[k].mi,z);
88
89 t[k].tag=min(t[k].tag,z);
90
91 }
92
93 inline void pushdown(int k)
94
95 {
96
97 if(t[k].tag==-1)return ;
98
99 update(k<<1,t[k].tag);
100
101 update(k<<1|1,t[k].tag);
102
103 t[k].tag=-1;
104
105 }
106
107 inline void build(int k,int x,int y)
108
109 {
110
111 int l=t[k].l=x,r=t[k].r=y,mid=(l+r)>>1;t[k].tag=-1;
112
113 if(l==r){t[k].mi=l==0?0:inf;return ;}
114
115 build(k<<1,l,mid);build(k<<1|1,mid+1,r);
116
117 pushup(k);
118
119 }
120
121 inline ll query(int k,int x)
122
123 {
124
125 int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
126
127 if(l==r)return t[k].mi;
128
129 pushdown(k);
130
131 if(x<=mid)return query(k<<1,x);else return query(k<<1|1,x);
132
133 }
134
135 inline void change(int k,int x,int y,ll z)
136
137 {
138
139 int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
140
141 if(l==x&&r==y){update(k,z);return;}
142
143 pushdown(k);
144
145 if(y<=mid)change(k<<1,x,y,z);
146
147 else if(x>mid)change(k<<1|1,x,y,z);
148
149 else change(k<<1,x,mid,z),change(k<<1|1,mid+1,y,z);
150
151 pushup(k);
152
153 }
154
155 int main()
156
157 {
158
159 freopen("input.txt","r",stdin);
160
161 freopen("output.txt","w",stdout);
162
163 n=read();x=read();y=read();
164
165 for1(i,n)
166
167 {
168
169 a[i].l=read()-x+1;a[i].r=read()-x+1;a[i].w=read();
170
171 if(a[i].l<=0)a[i].l=1;
172
173 }
174
175 sort(a+1,a+n+1,cmp);
176
177 build(1,0,y-x+1);
178
179 for1(i,n)
180
181 {
182
183 if(a[i].r<a[i].l)continue;
184
185 if(a[i].r<=0)continue;
186
187 if(a[i].l>y-x+1)continue;
188
189 ll t=query(1,a[i].l-1);
190
191 if(t!=inf)change(1,a[i].l,min(a[i].r,y-x+1),t+a[i].w);else break;
192
193 }
194
195 //for1(i,n)cout<<a[i].l<<‘ ‘<<a[i].r<<‘ ‘<<a[i].w<<endl;
196
197 //for1(k,8*n)cout<<t[k].l<<‘ ‘<<t[k].r<<‘ ‘<<t[k].mi<<‘ ‘<<t[k].tag<<endl;
198
199 ll ans=query(1,y-x+1);
200
201 printf("%lld\n",ans==inf?-1:ans);
202
203 return 0;
204
205 }