Concerto de Pandemic
Time limit2sMemory limit1024 MB
Place at most P concerts in non-quarantined cities on a cycle so the farthest fan's travel time is minimized, where each quarantined city passed through adds its delay.
- Level
Medium7 of 10
- Topics
- Binary search, Greedy, Shortest path
- Solved
- No attempts yet
Statement
There are cities numbered from 1 to . A bidirectional road connects city and city for , and city is connected to city 1 by a road as well. Each road takes 1 day to travel.
Due to a pandemic, cities impose a quarantine order on visitors. Whoever visits city is quarantined for exactly days in a government facility in that city. The order applies to all visitors, including those who only pass through the city without intending to stay.
Nawan is a rising young musician with die-hard fans. The -th fan lives in city . Surprisingly, no fan lives in a city that imposes a quarantine order.
Nawan has just released an album and wants to hold concerts for his fans. Over the objections of his team, Nawan insists that the concerts be held live and in person. He believes a virtual concert cannot convey his musical feeling.
After weighing the budget and resources, Nawan and his team agree to hold at most concerts. Concerts can be held only in cities without a quarantine order. Nawan has contacted all fans, and each fan agrees to attend exactly one concert. The only remaining question is which cities should host the concerts. Each fan goes to the venue that is closest in travel time. Venues have no capacity limit.
Nawan wants to hold the concerts in at most cities so that the longest travel time of any fan is as small as possible. You only need to output that minimum longest travel time.
Input
The first line contains four integers , , , (, ). These are the number of cities, the number of cities with a quarantine order, the number of fans, and the maximum number of concerts. Each of the next lines contains and (, ). All are distinct. The last line contains integers (), the city of each fan. No fan lives in a quarantine city, and all fans live in different cities.
Output
Output one integer on a line: the minimum longest travel time needed by any fan to reach a concert venue.