CF Round422 Div2 PC(水题)

这么水的题居然看了题解还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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值