





from __future__ import annotations






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:list[int]   ,   SCREAMING_SNAKE_CASE		:list[int]   ,   SCREAMING_SNAKE_CASE		:int   )      ->   Tuple:
 __lowerCAmelCase					:	Tuple      =       list(range(len(__lowerCamelCase   )   )   )
 __lowerCAmelCase					:	str      =       [v / w for v, w in zip(__lowerCamelCase   ,   __lowerCamelCase   )]
 index.sort(key=lambda SCREAMING_SNAKE_CASE   : ratio[i]   ,   reverse=__lowerCamelCase   )

 __lowerCAmelCase					:	float      =       0
 __lowerCAmelCase					:	list[float]      =       [0] * len(__lowerCamelCase   )
 for i in index:
  if weight[i] <= capacity:
   __lowerCAmelCase					:	str      =       1
   max_value += value[i]
   capacity -= weight[i]
  else:
   __lowerCAmelCase					:	int      =       capacity / weight[i]
   max_value += value[i] * capacity / weight[i]
   break

 return max_value, fractions


if __name__ == "__main__":
      import doctest

      doctest.testmod()






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:int   ,   SCREAMING_SNAKE_CASE		:list   )      ->   Dict:
 _enforce_args(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )
 if n == 0:
  return 0
 __lowerCAmelCase					:	Union[str, Any]      =       float("""-inf"""   )
 for i in range(1   ,   n + 1   ):
  __lowerCAmelCase					:	Union[str, Any]      =       max(
      SCREAMING_SNAKE_CASE   ,   prices[i - 1] + naive_cut_rod_recursive(n - i   ,   SCREAMING_SNAKE_CASE   )   )

 return max_revue






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:int   ,   SCREAMING_SNAKE_CASE		:list   )      ->   List[str]:
 _enforce_args(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )
 __lowerCAmelCase					:	List[str]      =       [float("""-inf"""   ) for _ in range(n + 1   )]
 return _top_down_cut_rod_recursive(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:int   ,   SCREAMING_SNAKE_CASE		:list   ,   SCREAMING_SNAKE_CASE		:list   )      ->   List[str]:
 if max_rev[n] >= 0:
  return max_rev[n]
 elif n == 0:
  return 0
 else:
  __lowerCAmelCase					:	str      =       float("""-inf"""   )
  for i in range(1   ,   n + 1   ):
   __lowerCAmelCase					:	List[Any]      =       max(
       SCREAMING_SNAKE_CASE   ,   prices[i - 1] + _top_down_cut_rod_recursive(n - i   ,   SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )   ,   )

  __lowerCAmelCase					:	List[str]      =       max_revenue

 return max_rev[n]






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:int   ,   SCREAMING_SNAKE_CASE		:list   )      ->   Union[str, Any]:
 _enforce_args(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )

 # length(max_rev) = n + 1, to accommodate for the revenue obtainable from a rod of
 # length 0.
 __lowerCAmelCase					:	Optional[int]      =       [float("""-inf"""   ) for _ in range(n + 1   )]
 __lowerCAmelCase					:	List[str]      =       0

 for i in range(1   ,   n + 1   ):
  __lowerCAmelCase					:	Optional[Any]      =       max_rev[i]
  for j in range(1   ,   i + 1   ):
   __lowerCAmelCase					:	Optional[int]      =       max(SCREAMING_SNAKE_CASE   ,   prices[j - 1] + max_rev[i - j]   )

  __lowerCAmelCase					:	Optional[int]      =       max_revenue_i

 return max_rev[n]






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:int   ,   SCREAMING_SNAKE_CASE		:list   )      ->   List[Any]:
 if n < 0:
  __lowerCAmelCase					:	Any      =       F'''n must be greater than or equal to 0. Got n = {n}'''
  raise ValueError(SCREAMING_SNAKE_CASE   )

 if n > len(SCREAMING_SNAKE_CASE   ):
  __lowerCAmelCase					:	Any      =       (
      """Each integral piece of rod must have a corresponding price. """
      F'''Got n = {n} but length of prices = {len(SCREAMING_SNAKE_CASE   )}'''
  )
  raise ValueError(SCREAMING_SNAKE_CASE   )






def 	_SCREAMING_SNAKE_CASE		(      )      ->   Optional[int]:
 __lowerCAmelCase					:	Tuple      =       [6, 10, 12, 15, 20, 23]
 __lowerCAmelCase					:	List[str]      =       len(SCREAMING_SNAKE_CASE   )

 # the best revenue comes from cutting the rod into 6 pieces, each
 # of length 1 resulting in a revenue of 6 * 6 = 36.
 __lowerCAmelCase					:	Union[str, Any]      =       36

 __lowerCAmelCase					:	Optional[int]      =       top_down_cut_rod(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )
 __lowerCAmelCase					:	List[str]      =       bottom_up_cut_rod(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )
 __lowerCAmelCase					:	int      =       naive_cut_rod_recursive(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )

 assert expected_max_revenue == max_rev_top_down
 assert max_rev_top_down == max_rev_bottom_up
 assert max_rev_bottom_up == max_rev_naive


if __name__ == "__main__":
      main()