7
7
from __future__ import annotations
8
8
9
9
10
- def latest_non_conflict (jobs : list [tuple [int , int , int ]], n : int ) -> int :
10
+ def latest_non_conflict (jobs : list [tuple [int , int , int ]], indx : int ) -> int :
11
11
"""
12
12
This function finds the latest job that does not conflict with
13
- the current job at index `n `.
13
+ the current job at index `indx `.
14
14
The jobs are given as (start_time, end_time, weight), and the
15
15
jobs should be sorted by end time.
16
16
It returns the index of the latest job that finishes before the
@@ -21,8 +21,8 @@ def latest_non_conflict(jobs: list[tuple[int, int, int]], n: int) -> int:
21
21
>>> latest_non_conflict([(1, 3, 50), (3, 4, 60), (5, 9, 70)], 2)
22
22
1
23
23
"""
24
- for j in range (n - 1 , - 1 , - 1 ):
25
- if jobs [j ][1 ] <= jobs [n ][0 ]:
24
+ for j in range (indx - 1 , - 1 , - 1 ):
25
+ if jobs [j ][1 ] <= jobs [indx ][0 ]:
26
26
return j
27
27
return - 1
28
28
@@ -44,14 +44,14 @@ def find_max_weight(jobs: list[tuple[int, int, int]]) -> int:
44
44
200
45
45
"""
46
46
# Sort jobs based on their end times
47
- jobs .sort (key = lambda x : x [1 ])
47
+ jobs .sort (key = lambda ele : ele [1 ])
48
48
49
49
# Initialize dp array to store the maximum weight up to each job
50
- n = len (jobs )
51
- dp = [0 ] * n
50
+ length = len (jobs )
51
+ dp = [0 ] * length
52
52
dp [0 ] = jobs [0 ][2 ] # The weight of the first job is the initial value
53
53
54
- for i in range (1 , n ):
54
+ for i in range (1 , length ):
55
55
# Include the current job
56
56
include_weight = jobs [i ][2 ]
57
57
latest_job = latest_non_conflict (jobs , i )
0 commit comments