Skip to content

Commit b0ffd60

Browse files
authored
Create activity_selection.py
1 parent 2c81da9 commit b0ffd60

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#Prints a maximum set of activities that can be done by a
2+
#single person, one at a time
3+
#n --> Total number of activities
4+
#s[]--> An array that contains start time of all activities
5+
#f[] --> An array that contains finish time of all activities
6+
7+
def print_max_activities(s, f):
8+
n = len(f)
9+
10+
# the first activity is always selected
11+
i = 0
12+
print(i, end=' ')
13+
14+
# for the rest
15+
for j in range(n):
16+
if s[j] >= f[i]:
17+
print(j, end=' ')
18+
i = j

0 commit comments

Comments
 (0)