思路:题目比较好懂的模拟题,用一个优先队列即可
模拟的时候要注意最后还会再开一次门,把剩下的人全部放进来,开门的时间并不一定是递增的,要自己排个序,还有就是要注意开门的时候是2 5这种数据,就是到第二个人到了开门,然后可以放5个人进来,这样不处理的话会RE
#include<bits/stdc++.h>
using namespace std;
const int maxn = 150000+7;
struct Node
{
char name[205];
int w;
int id;
bool operator < (const Node&a)const
{
if(w==a.w)
return id>a.id;
return w<a.w;
}
}p[maxn];
struct node
{
int t;
int peo;
}pp[maxn];
bool cmp(node a,node b)
{
return a.t<b.t;
}
int ans[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(ans,0,sizeof(ans));
int n,m,q;
scanf("%d%d%d",&n,&m,&q);
for(int i = 1;i<=n;i++)
{
scanf("%s%d",p[i].name,&p[i].w);
p[i].id = i;
}
for(int i = 1;i<=m;i++)
scanf("%d%d",&pp[i].t,&pp[i].peo);
sort(pp+1,pp+1+m,cmp);
priority_queue<Node>que;
int cnt = 1;int res = 1;
for(int i = 1;i<=m;i++)
{
int tim = pp[i].t;
for(;cnt<=tim;cnt++)
que.push(p[cnt]);
int lim = pp[i].peo;
for(int j = 1;j<=lim&&!que.empty();j++)
{
Node tmp = que.top();que.pop();
ans[res++]=tmp.id;
}
}
for(;cnt<=n;cnt++)
que.push(p[cnt]);
while(!que.empty())
{
Node tmp = que.top();
que.pop();
ans[res++]=tmp.id;
}
for(int i = 1;i<q;i++)
{
int x;
scanf("%d",&x);
printf("%s ",p[ans[x]].name);
}
int x;scanf("%d",&x);
printf("%s\n",p[ans[x]].name);
}
}