这么水的题居然看了题解还wa了四次简直是丢脸
思路倒是很简单的,就是我把每个区间用l和r分别保存,保存到
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define maxn 201000
#define ll long long
using namespace std;
const long long inf=1e18;
vector<pair<ll,ll> >l[maxn],r[maxn];
ll c[maxn];
int main()
{
int n,x;
ll ans;
while(~scanf("%d %d",&n,&x))
{
ans=inf;
for (int k=1;k<=n;k++)
{
ll lll,rr,cc;
scanf("%I64d %I64d %I64d",&lll,&rr,&cc);
l[lll].push_back(make_pair(rr-lll+1,cc));
r[rr].push_back(make_pair(rr-lll+1,cc));
}
for (int k=0;k<maxn;k++)
c[k]=inf;
//cout<<11111<<endl;
for (int i=1;i<=200000;i++)
{
for (int j=0;j<l[i].size();j++)
{
int val=(x-l[i][j].first);
if (val<0) continue;
if (c[val]!=inf) ans=min(c[val]+l[i][j].second,ans);
}
//cout<<i<<endl;
for (int j=0;j<r[i].size();j++)
{
c[r[i][j].first]=min(c[r[i][j].first],r[i][j].second);
}
}
if (ans!=inf)
printf("%I64d\n",ans);
else printf("-1\n");
}
return 0;
}