aboutsummaryrefslogtreecommitdiffstats
path: root/1235/main.py
blob: ab6c10713235c757c58081cb892659ec4dc89c01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python

import bisect
import typing


class Solution:
    def jobScheduling(
        self,
        startTime: typing.List[int],
        endTime: typing.List[int],
        profit: typing.List[int],
    ) -> int:
        jobs = sorted(zip(endTime, startTime, profit))

        number_of_jobs = len(profit)

        dp = [0] * (number_of_jobs + 1)

        for i, (current_end_time, current_start_time, current_profit) in enumerate(
            jobs
        ):
            index = bisect.bisect_right(
                jobs, current_start_time, hi=i, key=lambda x: x[0]
            )
            dp[i + 1] = max(dp[i], dp[index] + current_profit)

        return dp[number_of_jobs]


def main():
    solution = Solution()
    print(solution.jobScheduling())


if __name__ == "__main__":
    main()