代码
python">
from unittest.mock import patch
class Solution:
def func(self, number, days, item_max_num, item_price):
max_money = 0
for i in range(number):
max_money += item_max_num[i] * self.compute_max_price(item_price[i])
print(max_money)
return max_money
def compute_max_price(self, price_list):
max_price = 0
left_price = price_list[0]
right_price = price_list[0]
for cur_price in price_list[1:]:
if cur_price > right_price:
right_price = cur_price
else:
max_price += (right_price - left_price)
left_price = cur_price
right_price = cur_price
if left_price != right_price:
max_price += (right_price - left_price)
print(price_list, max_price)
return max_price
def input_args():
number = int(input('number:'))
days = int(input('days:'))
item_max_num = list(map(int, input('item price:').split()))
item_price = []
for i in range(days):
item_price.append(list(map(int, input('item price:').split())))
return number, days, item_max_num, item_price
mock_input_lst = [
"3",
"3",
"4 5 6",
"1 2 3",
"4 3 2",
"1 5 3",
]
with patch('builtins.input', side_effect=mock_input_lst):
number, days, item_max_num, item_price = input_args()
s = Solution()
s.func(number, days, item_max_num, item_price)