# 入力 # N # C # V # S1 S2 S3 … SV # T1 T2 T3 … TV # Y1 Y2 Y3 … YV # M1 M2 M3 … MV # 1行目に、町の数を表す整数 N (1≤N≤50) が与えられる。 # 2行目に、手持ちのお金を表す整数 C (0≤C≤300) が与えられる。 # 3行目に、道の数を表す整数 V (1≤V≤1500) が与えられる。 # 4行目に、Si (1≤Si{}:{}={}".format( before_town_index[roadIndex], after_town_index[roadIndex], restMoney, min(time_of_a_to_b[townIndex][money] + int(time_town_to_town[roadIndex]), \ # time_of_a_to_b[int(after_town_index[roadIndex])-1][restMoney] ) ) ) # print("{}+{}or{}".format( time_of_a_to_b[townIndex][money], int(time_town_to_town[roadIndex]), \ # time_of_a_to_b[int(after_town_index[roadIndex])-1][restMoney] ) ) # 今回移動した場合の時間か、すでに計算されているものがあり、その方が小さければ、そちら。 time_of_a_to_b[roadInfo.after_town_index][restMoney]=min(time_of_a_to_b[townIndex][money] + roadInfo.time_town_to_town, \ time_of_a_to_b[roadInfo.after_town_index][restMoney] ) #print(time_of_a_to_b[town_count-1]) # 全コストでループし、その中で一番小さいものを回答とする ans = INF for money in range(start_money): ans = min( ans, time_of_a_to_b[town_count-1][money] ) if ans == INF: print( -1 ) else: print( ans )