#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 100
#define mp make_pair
#define mid (l+r)/2
#define le node * 2
#define ri node * 2 + 1
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
//#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
#define gc getchar_unlocked
typedef long long ll;
typedef short int si;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef pair<double,ll>pdi;
const ll inf=2e18;
const ll mod=1e9+7;
const ld Pi=acos(-1) ;
ll n , m ;
ll A [1009] , B [1009] , C [1009] , D [1009] ;
ll Dp [1009][2] ;
int main () {
cin >> n >> m ;
for ( int i = 0 ; i < n ; i ++ ) {
cin >> A [i] >> B [i] >> C [i] >> D [i] ;
}
set < pair < ll , pll > > s ;
for ( int i = 0 ; i < n ; i ++ ) {
Dp [i][0] = ( A [i] == 1 ? D [i] : inf ) ;
Dp [i][1] = ( B [i] == m ? D [i] : inf ) ;
for ( auto u : s ) {
if ( A [i] <= u.fi && u.fi <= B [i] ) {
Dp [i][0] = min ( Dp [i][0] , u.se.fi + D [i] ) ;
Dp [i][1] = min ( Dp [i][1] , u.se.se + D [i] ) ;
}
}
s .ins ( { C [i] , { Dp [i][0] , Dp [i][1] } } ) ;
}
ll ans = inf ;
for ( int i = 0 ; i < n ; i ++ ) {
ans = min ( ans , Dp [i][0] + Dp [i][1] - D [i] ) ;
}
cout << ( ans >= inf ? -1 : ans ) << endl ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
9 ms |
512 KB |
Output is correct |
19 |
Correct |
9 ms |
512 KB |
Output is correct |
20 |
Correct |
10 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
11 ms |
512 KB |
Output is correct |
23 |
Correct |
8 ms |
512 KB |
Output is correct |
24 |
Correct |
9 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
9 ms |
512 KB |
Output is correct |
19 |
Correct |
9 ms |
512 KB |
Output is correct |
20 |
Correct |
10 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
11 ms |
512 KB |
Output is correct |
23 |
Correct |
8 ms |
512 KB |
Output is correct |
24 |
Correct |
9 ms |
512 KB |
Output is correct |
25 |
Runtime error |
4 ms |
640 KB |
Execution killed with signal 11 |
26 |
Halted |
0 ms |
0 KB |
- |