-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob_seq_greedy.py
54 lines (45 loc) · 1003 Bytes
/
job_seq_greedy.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
print("enter the size")
size=input()
size=int(size)
net=0
#defining lists
profits=list()
deadline=list()
sequence=list()
#taking input from the user
print("enter profits")
for i in range(size):
x=input()
x=int(x)
profits.append(x)
print("enter deadlines")
for i in range(size):
x=input()
x=int(x)
deadline.append(x)
for i in range(size):
sequence.append(999)
maxx=max(deadline)
for i in range(maxx):
max_profit=max(profits)
index=profits.index(max_profit)
if sequence[deadline[index]] == 999:
sequence[deadline[index]]=index
net=net+profits[index]
profits[index]=0
else:
j=index
while j>=0:
if sequence[j]==999:
sequence[j]=index
net=net+profits[index]
profits[index]=0
break
else:
j=j-1
print("sequence array")
for i in sequence:
if i!=999:
print(i)
net=str(net)
print("net profit is: "+net)