hdu 5437 Alisha’s Party

#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct point {
    int x,id;
    char na[201];
    bool operator <(const point & q) const
    {
        if (x==q.x) return q.id<id;
        return x<q.x;
    }
};
point pe[150001];
int nex[150001],a[150001];
int main()
{
    int t,n,m,z,i,x,y,w;
    while (~scanf("%d",&t))
    {
        while (t--)
        {
            scanf("%d %d %d",&n,&m,&z);
            memset(nex,0,sizeof(nex));
            for (i=1;i<=n;i++)
            {
                scanf("%s",pe[i].na);
                scanf("%d",&pe[i].x);
                pe[i].id=i;
            }
            while (m--)
            {
                scanf("%d %d",&x,&y);
                nex[x]+=y;
            }
            nex[n]=n;
            int ans=1;
            priority_queue<point> que;
            for (i=1;i<=n;i++)
            {
                que.push(pe[i]);
                while (nex[i]--)
                {
                    if (que.size()==0) break;
                    point temp=que.top(); que.pop();
                    a[ans++]=temp.id;
                }
            }
            while (z--)
            {
                scanf("%d",&w);
                if (z!=0) printf("%s ",pe[a[w]].na);
                else printf("%s
",pe[a[w]].na);
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/NWUACM/p/6626221.html