Princess Alisha invites her friends to come to her birthday party. Each of her friends will bring a gift of some value vv, and all of them will come at a different time. Because the lobby is not large enough, Alisha can only let a few people in at a time. She decides to let the person whose gift has the highest value enter first.
Each time when Alisha opens the door, she can decide to let pp people enter her castle. If there are less than pp people in the lobby, then all of them would enter. And after all of her friends has arrived, Alisha will open the door again and this time every friend who has not entered yet would enter.
If there are two friends who bring gifts of the same value, then the one who comes first should enter first. Given a query nn Please tell Alisha who the nn−th person to enter her castle is.
The first line of the input gives the number of test cases, TT, where 1≤T≤151≤T≤15.
In each test case, the first line contains three numbers k, mk, m and qq separated by blanks. kk is the number of her friends invited where 1≤k≤150,0001≤k≤150,000. The door would open mmtimes before all Alisha's friends arrive where 0≤m≤k0≤m≤k. Alisha will have qq queries where 1≤q≤1001≤q≤100.
The ii−th of the following kk lines gives a string BiBi, which consists of no more than 200200English characters, and an integer vi, 1≤vi≤108vi, 1≤vi≤108, separated by a blank. BiBi is the name of the ii−th person coming to Alisha's party and BiBi brings a gift of value vivi.
Each of the following mm lines contains two integers t(1≤t≤k)t(1≤t≤k) and p(0≤p≤k)p(0≤p≤k)separated by a blank. The door will open right after the tt−th person arrives, and Alisha will let pp friends enter her castle.
The last line of each test case will contain qqnumbers n1, ..., nqn1, ..., nq separated by a space, which means Alisha wants to know who are the n1−th, ..., nq−thn1−th, ..., nq−th friends to enter her castle.
Note: there will be at most two test cases containing n>10000n>10000.
For each test case, output the corresponding name of Alisha's query, separated by a space.
样例输入
1
5 2 3
Sorey 3
Rose 3
Maltran 3
Lailah 5
Mikleo 6
1 1
4 2
1 2 3
样例输出
Sorey Lailah Rose
题目解释:Alisha在第t个朋友到达的时候,会打开门让p个朋友进来,如果当前未进去的朋友数
题目思路:常规思路想的话,因为要让value大者先入,所以在每次轮到那几个朋友进入的情况下都需要对这几个朋友排序,且要记住他们的进入的序号,这样的话代码不仅会相当复杂,而且肯定会超时。 可以考虑使用优先队列,同时要注意考虑好最好如何输出名字。 ac代码:peo是arrive时的顺序,num是进入时的顺序,最后输出[num对应的peo].name即可 #include