File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std:: cmp:: Reverse ;
2
+ use std:: collections:: BinaryHeap ;
3
+
4
+ impl Solution {
5
+ pub fn get_order ( tasks : Vec < Vec < i32 > > ) -> Vec < i32 > {
6
+ let mut tasks = tasks;
7
+
8
+ for ( i, t) in tasks. iter_mut ( ) . enumerate ( ) {
9
+ t. push ( i as i32 ) ;
10
+ }
11
+ tasks. sort_by ( |a, b| a[ 0 ] . cmp ( & b[ 0 ] ) ) ;
12
+
13
+ let mut res = vec ! [ ] ;
14
+ let mut min_heap = BinaryHeap :: new ( ) ;
15
+ let ( mut i, mut time) = ( 0 , tasks[ 0 ] [ 0 ] ) ;
16
+
17
+ while !min_heap. is_empty ( ) || i < tasks. len ( ) {
18
+ while i < tasks. len ( ) && time >= tasks[ i] [ 0 ] {
19
+ min_heap. push ( Reverse ( vec ! [ tasks[ i] [ 1 ] , tasks[ i] [ 2 ] ] ) ) ;
20
+ i += 1 ;
21
+ }
22
+
23
+ if min_heap. is_empty ( ) {
24
+ time = tasks[ i] [ 0 ] ;
25
+ } else {
26
+ let pair = min_heap. pop ( ) . unwrap ( ) ;
27
+ let process_time = pair. 0 [ 0 ] ;
28
+ let index = pair. 0 [ 1 ] ;
29
+ time += process_time;
30
+ res. push ( index) ;
31
+ }
32
+ }
33
+ res
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments