#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define pb push_back
using namespace std;
int n,m,a[200009],b[200009],c[200009];
ll d[200009],ans;
ll mxv=1e9;
ll bt(int x,int l,int r)
{
if(x==-1)
{
if(l==1&&r==n)return 0;
else return mxv;
}
ll ret=mxv;
ret=bt(x-1,l,r);
if(l<=c[x]&&c[x]<=r)ret=min(ret,d[x]+bt(x-1,min(l,a[x]),max(r,b[x])));
return ret;
}
int main()
{
fast order
mxv*=mxv;
cin>>m>>n;
for(int i=0;i<m;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
ans=mxv;
for(int i=0;i<n;i++)
{
ans=min(ans,bt(i-1,a[i],b[i])+d[i]);
}
if(ans==mxv)cout<<-1;
else cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
187 ms |
404 KB |
Output is correct |
3 |
Execution timed out |
1054 ms |
384 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
187 ms |
404 KB |
Output is correct |
3 |
Execution timed out |
1054 ms |
384 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
187 ms |
404 KB |
Output is correct |
3 |
Execution timed out |
1054 ms |
384 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
187 ms |
404 KB |
Output is correct |
3 |
Execution timed out |
1054 ms |
384 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |