π Minimum Cost for Tickets β Python Solution Executed π―β
from bisect import bisect_left
m = int(raw_input())
days = list(map(int, raw_input().split()))
cost = list(map(int, raw_input().split()))
dp = {}
def solve(i, t):
if i == m:
return 0
if (i, t) in dp:
return dp[(i, t)]
ans = cost[0] + solve(i + 1, t)
if t:
ans = min(ans, solve(i + 1, t - 1))
j = bisect_left(days, days[i] + 7)
ans = min(ans, cost[1] + solve(j, t + 1))
j = bisect_left(days, days[i] + 30)
ans = min(ans, cost[2] + solve(j, t + 2))
dp[(i, t)] = ans
return ans
https://whatsapp.com/channel/0029VahiS3p2v1IyoS891Y1g
print(solve(0, 0))
π WhatsApp Channel:
https://whatsapp.com/channel/0029VahiS3p2v1IyoS891Y1g
β Stay connected & share with your friends for more coding solutions, OA updates, and placement support!