Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Station:
- def __init__(self, dist_from_a, cost, distancePerOneLitter):
- self.gaz_count = dist_from_a / distance_for_one_liter
- self.cost = cost
- def __str__(self):
- return "(" + str(self.gaz_count) + " " + str(self.cost) + ")"
- def get_cost(cost_str):
- a, b = cost_str.split('.')
- b = int(b)
- if b < 10:
- b *= 10
- return int(a) * 100 + b
- if __name__ == "__main__":
- distance = int(input())
- nums = input().split(" ")
- capacity = int(nums[0])
- distance_for_one_liter = int(nums[1])
- money_spend_in_A = get_cost(nums[2])
- stations_count = int(nums[3])
- stations = []
- stations.append(Station(0, 0, distance_for_one_liter))
- for i in range(stations_count):
- nums = input().split(" ")
- dist_from_a = int(nums[0])
- cost = get_cost(nums[1])
- stations.append(Station(dist_from_a, cost, distance_for_one_liter))
- d = []
- d.append(0)
- for i in range(1, len(stations)):
- costs = []
- all_costs = []
- for j in range(len(d)):
- if float(capacity) / 2 - 0.001 <= stations[i].gaz_count - stations[j].gaz_count <= capacity + 0.001:
- costs.append(d[j] + 2000 + (stations[i].gaz_count - stations[j].gaz_count) * stations[i].cost)
- if stations[i].gaz_count - stations[j].gaz_count <= capacity + 0.001:
- all_costs.append(d[j] + 2000 + (stations[i].gaz_count - stations[j].gaz_count) * stations[i].cost)
- if len(costs) > 0:
- d.append(sorted(costs)[0])
- else:
- d.append(sorted(all_costs)[0])
- gaz_to_end = distance / distance_for_one_liter
- station_ids_to_go_to_end = []
- for stationId in range(len(stations)):
- if stations[stationId].gaz_count > gaz_to_end - capacity - 0.0001:
- station_ids_to_go_to_end.append(stationId)
- costs_to_end = []
- for station_to_end_id in station_ids_to_go_to_end:
- costs_to_end.append(d[station_to_end_id])
- intValue = str(int(sorted(costs_to_end)[0] + money_spend_in_A))
- print(intValue[:-2], ".", intValue[-2:], sep="")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement