2014 Asia Shanghai Regional Contest H

Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others.

One day, there is another tribe become their target. The strong tribe has decide to terminate them!


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#define LL long long
#define WW freopen("in.txt","r",stdin)
#define RR freopen("out.txt","w",stdout)
#define INF 0x3f3f3f3f

using namespace std;
const int maxn = 100100;

class My
{
public:

    int At,Df;
    bool operator < (const struct My a)const
    {
        return At == a.At ? Df > a.Df : At > a.At;
    }
};

class Enemy
{
public:
    int At,Df;
    bool operator < (const struct Enemy a)const
    {
        return Df == a.Df ? At > a.At : Df > a.Df;
    }
};

My a[maxn];
Enemy b[maxn];

int main()
{
    int T;
    scanf("%d",&T);
    int cas = 0;
    while(T--)
    {
        int n,m;

        scanf("%d%d",&n,&m);

        for(int i=0;i<n;i++)
        {
            scanf("%d %d",&a[i].At,&a[i].Df);
        }
        for(int i=0;i<m;i++)
        {
            scanf("%d %d",&b[i].At,&b[i].Df);
        }
        sort(a,a+n);
        sort(b,b+m);

        multiset<int > S;
        int j = 0;
        int num = n;
        bool flag = true;
        for(int i=0;i<m;i++)
        {
            while(j < n && a[j].At >= b[i].Df)
                S.insert(a[j++].Df);
            if(S.empty())
            {
                flag = false;
                break;
            }
            multiset<int >::iterator it;
            it = S.lower_bound(b[i].At+1);
            if(it == S.end())
            {
                S.erase(S.begin());
                num--;
            }
            else
                S.erase(it);
        }
        if(!flag)
            printf("Case #%d: -1\n",++cas);
        else
            printf("Case #%d: %d\n",++cas,num);

    }

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值