Tom is performing an experiment in which he has to select N products. Each product has two attributes i.e. energy and weight. All the products are either manufactured by Reds Ltd. or Blues Ltd. The products manufactured by Blues Ltd. cannot function alone and need to be selected with some other product of the same company. The products from Reds Ltd., on the other hand, can be selected independently. Tom has to select products such that the total weight of the selected products does not exceed the weight W and the selected products have the maximum total energy value. Write an algorithm to help Tom find the maximum energy.
Answer :
N,W = map(int,input().split())
list = []*(N+1)
a=[]
b=[]
sum = 0
for i in range(N):
e,m,c = map(int,input().split())
list.append(e)
list.append(m)
list.append(c)
list=[list[i:i+3] for i in range(0, len(list), 3)]
for i in range(N):
ele1=list[i][2]
a.append(ele1)
for j in range(N):
ele2=list[j][0]
b.append(ele2)
for k in range(N):
if a[k] == 1:
sum += b[k]
for x in range(N):
if a[x] == 0:
if((sum + b[x]) < W):
print(sum+b[x])
break
Answers
Answer:
Phoneix Classes has opened for enrollment for providing coaching of JEE. Students can enroll their names or cancel the enrollment by filling the application form at the office. Names of more than one student can be added in one application form. A program is developed in Python using List data type (identifier/variable name “L”) to maintain a list of the names of individual student that have enrolled for the course. The element of list is a string containing name of a student. A student’s name is added in the list at the time of enrollment and removed from the list on cancellation. Write the possible python statement for any four of the following five operations (i) Enroll name of a single applicant at the end. (string data type with identifier/variable name “Name”) (ii) Enroll names of more than one applicant provided in a list. (list data type with