SSEC Coding Contest-4 Problem 4

PROBLEM CODE - SSEC0018

There is an operation going on where cement bags are getting loaded on a truck. The cement bags are present as a stack of bags and every worker has to pull the bag from the bottom. So every time a bag is removed less energy will be required next time. Now you are given the energies required to pull the bags and load it in the truck and the energy of lifters. The energy required to pull bags goes down with the percentage of the previous bag. Alot the lifters efficiently so that their energies don’t go to waste as well as mark the stack of bags NS(Not Sufficient ) for which there is no suitable lifter with sufficient energy is present.

Example

  1. You have N no of test cases where 0<N<5
  2. Second input will be no of stacks S (for less complexity no of lifters as well as a stack is same)
    Where 0<S<10

Now the input is in order of No of bags in the stack, associated energy required, the energy of a lifter(in any order).

1

3
4
2.5
10
3
1.10
3
2
6.40
2

  • 1 is the no of test cases
  • Here 3 denotes 3 stacks will be given
  • 4 bags in one stack
  • 2.5 in this 2 is the initial energy required by the bag and 5 in(2.5) is 5% less of the initial will be
    required next time.
  • 10 is the total energy of a lifter.

OUTPUT

  • It must be in this format - { No of bags in the stack} – {Initial Energy.Percentage} – {Assigned Lifter’s energy or NS}

4 – 2.5 – NS
3 – 1.10 – 3
2 – 6.40 – 10

SOLUTION

def sassign(abags, abagws, apfac, alifters):
awighs = []
aene = []
n = 0
ene = 0
prevene = 0
assig = alifters.copy()
for i in abagws:
    pfactor = apfac[n]
    prevene = i
    ene = prevene
    for p in range(abags[n] - 1):
        ene = ene + (prevene - (prevene / 100) * pfactor)
        prevene = prevene - (prevene / 100) * pfactor

    aene.append(ene)
    n = n + 1

a2lifters = alifters.copy()
a2ene = aene.copy()
# print(aene)
for p in range(len(alifters)):
    if max(a2ene) < max(a2lifters):
        assig[aene.index(max(a2ene))] = max(a2lifters)
        a2lifters.remove(max(a2lifters))

    else:
        assig[aene.index(max(a2ene))] = "NS"

    a2ene.remove(max(a2ene))

for a in range(len(abags)):
    print(
        "{} -- {} -- {}".format(
            abags[a], str(abagws[a]) + "." + str(apfac[a]), assig[a]
        )
    )


for p in range(int(input())):
bags = []
bagws = []
lifters = []
pfac = []
inA = int(input())
for a in range(inA):
    bags.append(int(input()))
    bgws, pfactr = input().split(".")
    bagws.append(int(bgws))
    pfac.append(int(pfactr))
    lifters.append(int(input()))
sassign(bags, bagws, pfac, lifters)