Alisha 举办聚会,会在一定朋友到达时打开门,并允许相应数量的朋友进入,带的礼物价值大的先进,最后一个人到达之后放外面的所有人进来。用优先队列模拟即可。需要定义朋友结构体,存储每个人的到达顺序以及携带礼品价值,并重载<运算符。然后模拟即可。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 150000 + 500;
struct fri{
    int v;int id;
    friend  bool operator < (const fri &a,const fri &b){
        return a.v<b.v||(a.v==b.v&&a.id>b.id);
    }
    fri (int  v,int id) :v(v),id(id){}
};

priority_queue <fri> pq;
char name[maxn][450];
int v[maxn],id[maxn];
pair <int,int> tn[maxn];///开门时间及允许进入人数
int qe[maxn];
int tq[maxn];

int main(){
    int t,k,m,q;
    while(~scanf("%d",&t)){
        while(t--){
            scanf("%d%d%d",&k,&m,&q);
            for(int i=0;i<k;i++)
                scanf("%s%d",name[i],&v[i]);
            for(int i=0;i<m;i++)
                scanf("%d%d",&tn[i].first,&tn[i].second);
            sort(tn,tn+m);
            int pernum = 0,cnt = 0,T = 0;
            for(int i=0;i<k;i++){
                    cnt++;
                    pq.push(fri(v[i],i));
                    while(pernum != m&& tn[pernum].first <= cnt){
                        int enternum = tn[pernum].second;
                        while(enternum && !pq.empty()){
                                fri ss = pq.top();pq.pop();
                                tq[T++] = ss.id;
                                enternum--;
                              }
                        pernum++;
                    }
                }
            while(!pq.empty()){
                fri ss = pq.top();pq.pop();
                tq[T++] = ss.id;
            }
            for(int i=0;i<q;i++) {
                    scanf("%d",&qe[i]);
                    if(!i) printf("%s",name[tq[qe[i]-1]]);
                    else printf(" %s",name[tq[qe[i]-1]]);
            }
            printf("\n");
        }
    }
    return 0;
}