Advertisement
1sairandhri

cutting rods

Apr 11th, 2020
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. def find_cur_profits(size, length, salePrice, costPerCut):
  2.     totalUniformRods = length//size
  3.     cuts = totalUniformRods -1 if length % size == 0 else totalUniformRods #number of cuts during process;
  4.     currentProfits = totalUniformRods * salePrice * size - costPerCut * cuts;
  5.     return currentProfits
  6.  
  7. def sol(costPerCut, salePrice, lengths):
  8.     maxProfit = 0
  9.     for size in range(1,max(lengths)+1):
  10.         profits = 0
  11.         for i in range(len(lengths)):
  12.             if(size > lengths[i]):
  13.                 continue;
  14.             currentProfits = find_cur_profits(size, lengths[i], salePrice, costPerCut)
  15.             if(currentProfits > 0):
  16.                 profits += currentProfits;
  17.         if(profits > maxProfit):
  18.             maxProfit = profits
  19.     return maxProfit
  20. sol(1,10,[30,59,110]) #1913
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement