Codeforces Round #422 (Div. 2), problem: (C) Hacker, pack your bags Solution In C/C++

#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
ll ans,c[200101],n,x,L,R,cc;
vector<pair<ll,ll> >l[200101],r[200101];
int main(){
scanf(“%lld%lld”,&n,&x);
for(int i=1;i<=n;i++){
scanf(“%lld%lld%lld”,&L,&R,&cc);
l[L].push_back(make_pair(R-L+1,cc));
r[R].push_back(make_pair(R-L+1,cc));
}
memset(c,0x3f3f,sizeof(c));ans=c[0];
for(int i=1;i<200100;i++){
for(int j=0;j<l[i].size();j++)l[i][j].first>=x?0:ans=min(ans,c[x-l[i][j].first]+l[i][j].second);
for(int j=0;j<r[i].size();j++)c[r[i][j].first]=min(c[r[i][j].first],r[i][j].second);
}
printf(“%lld”,ans==c[0]?-1:ans);
return 0;
}

#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
ll ans,c[200101],n,x,L,R,cc;
vector<pair<ll,ll> >l[200101],r[200101];
int main(){
scanf(“%lld%lld”,&n,&x);
for(int i=1;i<=n;i++){
scanf(“%lld%lld%lld”,&L,&R,&cc);
l[L].push_back(make_pair(R-L+1,cc));
r[R].push_back(make_pair(R-L+1,cc));
}
memset(c,0x3f3f,sizeof(c));ans=c[0];
for(int i=1;i<200100;i++){
for(int j=0;j<l[i].size();j++)l[i][j].first>=x?0:ans=min(ans,c[x-l[i][j].first]+l[i][j].second);
for(int j=0;j<r[i].size();j++)c[r[i][j].first]=min(c[r[i][j].first],r[i][j].second);
}
printf(“%lld”,ans==c[0]?-1:ans);
return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Supernatural: Wayward Special #1 Preview: Winchesters Split Up

Fans of the long-running television phenomenon Supernatural are in for a fresh dose of nostalgia and hunter drama with the upcoming release of the...

The Real Truth About Viral Kitchen Gadgets Before You Buy

📢 As an Amazon Associate, I earn from qualifying purchases.If you had told me six months ago that a single purchase would change how...

Bird flu could devastate Macquarie Island. Why are we removing the scientists we need to understand it?

Macquarie Island, a remote sub-Antarctic wildlife haven situated midway between Tasmania and Antarctica, is confronting an imminent ecological crisis. As the highly pathogenic H5N1...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!