Untitled
unknown
plain_text
2 years ago
844 B
5
Indexable
#python districts = input().split(',') n = int(input()) stations = [] for _ in range(n): station_data = input().split(':') station_id = int(station_data[0]) areas = station_data[1].split(',') stations.append({"id": station_id, "areas": areas}) stations.sort(key=lambda x: x["id"]) selected_stations = [] while districts: best_station = None max_coverage = 0 for station in stations: station_areas = station["areas"] coverage = len(set(station_areas) & set(districts)) if coverage > max_coverage: max_coverage = coverage best_station = station if best_station: selected_stations.append(best_station["id"]) districts = list(set(districts) - set(best_station["areas"])) print(','.join(str(station_id) for station_id in sorted(selected_stations)))
Editor is loading...
Leave a Comment