This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=1e5+5;
const ll inf=2e18;
ll n,m,a[maxN+1],b[maxN+1],c[maxN+1],d[maxN+1],dp[maxN+1],f[maxN+1];
bool intersect(ll l,ll r,ll mid)
{
return (l<=mid&&mid<=r);
}
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>m>>n;
for(int i=1;i<=m;i++)
{
cin>>a[i]>>b[i]>>c[i]>>d[i];
dp[i]=inf;
f[i]=inf;
}
dp[0]=0;
f[0]=0;
for(int i=1;i<=m;i++)
{
for(int j=0;j<i;j++)
{
if(!j)
{
if(intersect(a[i],b[i],1))
{
dp[i]=min(dp[i],dp[j]+d[i]);
}
if(intersect(a[i],b[i],n))
{
f[i]=min(f[i],f[j]+d[i]);
}
}
else
{
if(intersect(a[i],b[i],c[j]))
{
dp[i]=min(dp[i],dp[j]+d[i]);
f[i]=min(f[i],f[j]+d[i]);
}
}
}
//cout<<i<<" "<<dp[i]<<" "<<f[i]<<'\n';
}
ll ans=inf;
for(int i=1;i<=m;i++)
{
ans=min(ans,dp[i]+f[i]-d[i]);
}
if(ans==inf)
{
cout<<-1;
}
else cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |