HDU 6003 Problem Buyer] [small heap root

Can be any k, you may not have seen the election, and then pick a number of possible to choose
the interval and m values are sorted, an order r l interval by sequencing two rows enumerate the m value, small roots heap help maintain the right point range of the current value of the enumeration of Korea, so easy to delete range, and then the rest is not possible, so ans = max (n-size + 1)
Note to eject a complete enumeration range, indicating that the zone belongs to the current enumeration value

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int N=100005;
int T,n,m,a[N],ans,cas;
pair<int,int>b[N];
int read()
{
    int r=0,f=1;
    char p=getchar();
    while(p>'9'||p<'0')
    {
        if(p=='-')
            f=-1;
        p=getchar();
    }
    while(p>='0'&&p<='9')
    {
        r=r*10+p-48;
        p=getchar();
    }
    return r*f;
}
int main()
{
    T=read();
    while(T--)
    {
        n=read(),m=read(),ans=0;
        for(int i=1;i<=n;i++)
            b[i].first=read(),b[i].second=read();
        for(int i=1;i<=m;i++)
            a[i]=read();
        sort(a+1,a+1+m);
        sort(b+1,b+1+n);
        priority_queue<int,vector<int>,greater<int> >q;
        for(int i=1,j=1;i<=m;i++)
        {
            while(j<=n&&b[j].first<=a[i])
                q.push(b[j++].second);
            while(!q.empty()&&q.top()<a[i])
                q.pop();
            if(q.empty())
            {
                ans=-1;
                break;
            }
            ans=max(ans,n-(int)q.size()+1);
            q.pop();//!
        }
        if(ans==-1) 
            printf("Case #%d: IMPOSSIBLE!\n",++cas);
        else
            printf("Case #%d: %d\n",++cas,ans);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/lokiii/p/11017888.html