File tree 1 file changed +12
-11
lines changed
1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change 5
5
6
6
"""
7
7
8
+
8
9
def interval_scheduling (stimes , ftimes ):
9
10
index = list (range (len (stimes )))
10
11
# sort according to finish times
11
12
index .sort (key = lambda i : ftimes [i ])
12
-
13
+
13
14
maximal_set = set ()
14
15
prev_finish_time = 0
15
16
for i in index :
16
17
if stimes [i ] >= prev_finish_time :
17
18
maximal_set .add (i )
18
19
prev_finish_time = ftimes [i ]
19
-
20
+
20
21
return maximal_set
21
-
22
-
23
- n = int (input ('Enter number of activities: ' ))
24
- stimes = input ('Enter the start time of the {} activities in order: '
25
- .format (n )).split ()
22
+
23
+
24
+ n = int (input ("Enter number of activities: " ))
25
+ stimes = input ("Enter the start time of the {} activities in order: " .format (n )).split ()
26
26
stimes = [int (st ) for st in stimes ]
27
- ftimes = input ('Enter the finish times of the {} activities in order: '
28
- .format (n )).split ()
27
+ ftimes = input (
28
+ "Enter the finish times of the {} activities in order: " .format (n )
29
+ ).split ()
29
30
ftimes = [int (ft ) for ft in ftimes ]
30
-
31
+
31
32
ans = interval_scheduling (stimes , ftimes )
32
- print (' A maximum-size subset of activities that are mutually compatible is' , ans )
33
+ print (" A maximum-size subset of activities that are mutually compatible is" , ans )
You can’t perform that action at this time.
0 commit comments