Untitled
unknown
plain_text
2 years ago
1.2 kB
7
Indexable
def profit_maximization(number_of_days, price_list): if len(price_list) <= 1: return 0, 0 price_list_test = price_list[:] favorable_for_buy = min(price_list_test) price_list_test = price_list_test[price_list_test.index(favorable_for_buy):] favorable_for_selling = max(price_list_test) buy_day = price_list.index(favorable_for_buy) + 1 sell_day = price_list.index(favorable_for_selling) + 1 if buy_day >= sell_day: return 0, 0 else: return buy_day, sell_day test_cases = [ (2, [10, 3]), (5, [10, 3, 5, 3, 11]), (4, [5, 8, 6, 10]), (5, [5, 3, 4, 7, 6]), (6, [1, 8, 3, 7, 1, 6]), (5, [10, 5, 6, 7, 9]), (0, []), (5, [5, 5, 5, 5, 5]), (1, [5]), (2, [5, 6]), (5, [10, 9, 8, 7, 6]), (5, [1, 2, 3, 4, 5]), (5, [10, 5, 8, 4, 9]), (3, [5, 5, 5]), (5, [2, 3, 5, 9, 7]), (5, [1, 5, 3, 9, 6]), (3, [5, 5, 5]), (5, [9, 4, 8, 5, 10]), (3, [5, 5, 5]), (5, [1, 7, 3, 9, 6]), ] for i, (n, prices) in enumerate(test_cases): buy_day, sell_day = profit_maximization(n, prices) print(f"Тест {i + 1}: Входные данные: n = {n}, prices = {prices}. Результат: {buy_day}, {sell_day}")
Editor is loading...