# Untitled

a guest
Dec 11th, 2019
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. class Station:
2.     def __init__(self, dist_from_a, cost, distancePerOneLitter):
3.         self.gaz_count = dist_from_a / distance_for_one_liter
4.         self.cost = cost
5.
6.     def __str__(self):
7.         return "(" + str(self.gaz_count) + " " + str(self.cost) + ")"
8.
9.
10. def get_cost(cost_str):
11.     a, b = cost_str.split('.')
12.     b = int(b)
13.     if b < 10:
14.         b *= 10
15.
16.     return int(a) * 100 + b
17.
18.
19. if __name__ == "__main__":
20.     distance = int(input())
21.
22.     nums = input().split(" ")
23.     capacity = int(nums[0])
24.     distance_for_one_liter = int(nums[1])
25.     money_spend_in_A = get_cost(nums[2])
26.     stations_count = int(nums[3])
27.
28.     stations = []
29.     stations.append(Station(0, 0, distance_for_one_liter))
30.     for i in range(stations_count):
31.         nums = input().split(" ")
32.         dist_from_a = int(nums[0])
33.         cost = get_cost(nums[1])
34.         stations.append(Station(dist_from_a, cost, distance_for_one_liter))
35.
36.     d = []
37.     d.append(0)
38.     for i in range(1, len(stations)):
39.         costs = []
40.         all_costs = []
41.         for j in range(len(d)):
42.             if float(capacity) / 2 - 0.001 <= stations[i].gaz_count - stations[j].gaz_count <= capacity + 0.001:
43.                 costs.append(d[j] + 2000 + (stations[i].gaz_count - stations[j].gaz_count) * stations[i].cost)
44.             if stations[i].gaz_count - stations[j].gaz_count <= capacity + 0.001:
45.                 all_costs.append(d[j] + 2000 + (stations[i].gaz_count - stations[j].gaz_count) * stations[i].cost)
46.         if len(costs) > 0:
47.             d.append(sorted(costs)[0])
48.         else:
49.             d.append(sorted(all_costs)[0])
50.
51.     gaz_to_end = distance / distance_for_one_liter
52.
53.
54.     station_ids_to_go_to_end = []
55.     for stationId in range(len(stations)):
56.         if stations[stationId].gaz_count > gaz_to_end - capacity - 0.0001:
57.             station_ids_to_go_to_end.append(stationId)
58.
59.     costs_to_end = []
60.     for station_to_end_id in station_ids_to_go_to_end:
61.         costs_to_end.append(d[station_to_end_id])
62.
63.     intValue = str(int(sorted(costs_to_end)[0] + money_spend_in_A))
64.     print(intValue[:-2], ".", intValue[-2:], sep="")
RAW Paste Data