#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll inf=1e18;
struct device{
int i, a, b, c, d;
ll dp[2]={inf, inf};
bool operator<(const device B)const{
return b<B.b;
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin>>n>>m;
vector<device> devs(n);
for(int i=0; i<n; i++){
cin>>devs[i].a>>devs[i].b>>devs[i].c>>devs[i].d;
devs[i].i=i;
}
sort(devs.begin(),devs.end());
ll ans=inf;
for(int i=0; i<n; i++){
if(devs[i].a==1) devs[i].dp[0]=devs[i].dp[1]=devs[i].d;
for(int j=0; j<n; j++){
if(devs[i].i>devs[j].i && devs[i].a<=devs[j].c && devs[j].c<=devs[i].b){
devs[i].dp[0]=min(devs[i].dp[0],devs[j].dp[0]+devs[i].d);
devs[i].dp[1]=min(devs[i].dp[1],devs[j].dp[0]+devs[i].d);
}else if(devs[j].i>devs[i].i && devs[j].a<=devs[i].c && devs[i].c<=devs[j].b){
devs[i].dp[1]=min(devs[i].dp[1],min(devs[j].dp[0]+devs[i].d,devs[j].dp[1]+devs[i].d));
}
}
if(devs[i].b==m){
ans=min(devs[i].dp[0],devs[i].dp[1]);
}
}
if(ans==inf) cout<<-1<<endl;
else cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |