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;
vector<tuple<long long,long long,long long,long long> > v;
long long n,m;
long long f(long long poz,long long l,long long r)
{
if (poz==-1)
{
if (l==1 && r==n) return 0;
return 1000000;
}
long long op1=f(poz-1,l,r);
long long op2=10000000;
long long a=get<0>(v[poz]),b=get<1>(v[poz]),c=get<2>(v[poz]);
if (c>=l && c<=r) op2=f(poz-1,min(a,l),max(b,r))+get<3>(v[poz]);
return min(op1,op2);
}
int main()
{
cin>>m>>n;
for (long long i=0;i<m;i++)
{
long long a,b,c,d;
cin>>a>>b>>c>>d;
v.push_back({a,b,c,d});
}
long long odg=1000000;
for (long long i=m-1;i>=0;i--)
odg = min(odg,get<3>(v[i])+f(i-1,get<0>(v[i]),get<1>(v[i])));
if (odg>=1000000) odg=-1;
cout<<odg<<endl;
return 0;
}
# | 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... |