Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bar:
- pass
- class Choice:
- pass
- #file with input data
- tmpFile = open("Pyfood.txt", "r")
- barsKinds, BajtazarsMoney = [int(x) for x in tmpFile.readline().split(" ")]
- barsPrices = [int(x) for x in tmpFile.readline().split(" ")]
- barsAmount = [int(x) for x in tmpFile.readline().split(" ")]
- barsList = []
- for x in range(barsKinds):
- newBar = Bar()
- newBar.price = barsPrices[x]
- newBar.amount = barsAmount[x]
- barsList.append(newBar)
- def findBestOneToBuy(barsList):
- """ Finds best bar to buy (with biggest profit) and returns this as a structure Choice """
- bestChoice = Choice()
- bestChoice.idx = 0
- bestChoice.profit = 0
- for x in range(len(barsList)): #check every possible condition
- tmpChoice = Choice()
- tmpChoice.idx = x
- tmpChoice.profit = 0
- if (barsList[x].amount == 0 or
- barsList[x].price > BajtazarsMoney) : continue
- moneySaved = 0
- moneySpent = 0
- for i in range(x): # for every possible condition count profit
- print(i)
- if barsList[i].amount > 0 : moneySaved += barsList[i].price
- moneySaved += barsList[x].price
- moneySpent = barsList[x].price
- tmpChoice.profit = moneySaved/moneySpent
- if tmpChoice.profit > bestChoice.profit : bestChoice = tmpChoice
- print(tmpChoice.profit)
- return bestChoice
- def buyBar(idx, barsList):
- """ Takes idx of bar you want to buy and decreases amounts of
- bars in barsList. returns price to pay and totalValue of stolen goods
- as a tuple """
- totalValue = 0
- for bar in range(idx):
- if barsList[bar].amount >0 :
- barsList[bar].amount -= 1
- totalValue += barsList[bar].price
- totalValue += barsList[idx].price
- barsList[idx].amount -= 1
- return barsList[idx].price, totalValue
- moneyGained = 0
- while True:
- barToBuy = findBestOneToBuy(barsList)
- print("chosen", barToBuy.idx+1)
- if barsList[barToBuy.idx].price > BajtazarsMoney : break
- moneySpent, tmpMoney = buyBar(barToBuy.idx, barsList)
- BajtazarsMoney -= moneySpent
- moneyGained += tmpMoney
- print(moneyGained)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement