#P15607. [ICPC 2021 Jakarta R] Concerto de Pandemic

[ICPC 2021 Jakarta R] Concerto de Pandemic

题目描述

There are NN cities numbered from 11 to NN. There is a bi-directional road connecting city ii to city i+1i + 1 for 1i<N1 \leq i < N and city NN to city 11. Each road takes 11 day to travel.

Due to a pandemic situation, there are MM cities that impose a quarantine order for any visitors to mitigate the pandemic spread in those cities. Specifically, whenever someone visits city CiC_i, they will be quarantined for a duration of exactly TiT_i days in a government-provided facility in that city. The order applies to any visitor including those who don't intend to stay in that city, e.g., only transiting.

Nawan is a rising young musician who already has KK die-hard fans. The ithi^{th} fan lives in city DiD_i, and surprisingly enough, none of the fans live in a city that imposes a quarantine order for visitors. Nawan has just released an album and now he wants to hold concerts for his die-hard fans. Despite rejections from his team, Nawan insists that the concert must be held live and in person; he believes that he wouldn't be able to convey his "musical feeling" to his fans through a virtual concert.

After considering the budget and their resource, Nawan and his team agree to hold at most PP concerts. Moreover, These concerts can only be held in cities that are not imposing any quarantine order for visitors. Nawan has contacted all of his fans and each of them agrees to attend only 11 concert. The only remaining issue is in choosing the cities where Nawan should have a concert.

Each of the fans will attend a concert in which the venue requires the minimum travel time from their city. Each concert venue has no maximum capacity. Nawan wishes to hold the concerts in at most PP cities such that the longest travel time among all of his fans is as minimum as possible. Since Nawan needs to practice and prepare for the concerts, he asked you to choose the cities in which he should have a concert such that the longest required travel time by any fan is as minimum as possible; you only need to output the minimum longest travel time.

For example, let N=10N = 10, M=4M = 4, C1..4={1,4,6,7}C_{1..4} = \{1, 4, 6, 7\}, T1..4={2,4,2,5}T_{1..4} = \{2, 4, 2, 5\}, K=3K = 3, D1..3={2,5,8}D_{1..3} = \{2, 5, 8\}, and P=2P = 2. In this example, the concert venues should be in city 55 and city 1010 with a longest travel time of only 44 days.

  • The 1st1^{st} fan at city 22 will go to the concert at city 1010, i.e. 212 \rightarrow 1 (quarantined for 22 days) 10\rightarrow 10, for a total travel time of 44 days.
  • The 2nd2^{nd} fan at city 55 will go to the concert at city 55 where no travel is needed.
  • The 3rd3^{rd} fan at city 88 will go to the concert at city 1010. i.e. 89108 \rightarrow 9 \rightarrow 10, for a total travel time of 22 days.

输入格式

Input begins with a line containing four integers NN MM KK PP (1M<N2000001 \leq M < N \leq 200\,000; 1K,PNM1 \leq K, P \leq N - M) representing the number of cities, the number of cities that impose a quarantine order, the number of Nawan's die-hard fans, and the maximum number of concerts to be held, respectively. The next MM lines each contains two integers CiC_i TiT_i (1CiN1 \leq C_i \leq N; 1Ti2000001 \leq T_i \leq 200\,000) representing the city that has a quarantine order and its quarantine duration, respectively. It is guaranteed that all CiC_i are unique. The last line contains KK integers DiD_i (1DiN1 \leq D_i \leq N) representing the city in which the ithi^{th} fan lives in. It is guaranteed that no fan lives in a city that imposes a quarantine order for visitors, and all fans live in a different city.

输出格式

Output contains an integer in a line representing the minimum longest travel time needed by any fan to reach a concert venue.

10 4 3 2
1 2
4 4
6 2
7 5
2 5 8
4
8 1 3 5
1 5
4 2 7
0
5 2 2 1
1 14
2 14
3 5
1

提示

Explanation for the sample input/output #2

Nawan can hold a private concert for each of his fans, i.e. the concert venues should be in cities 22, 44, and 77.