hdoj4864 Task

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 101000;
struct Node
{
    int xi,yi;
};

Node mac[N];
Node pro[N];
int cmp(Node a,Node b)
{
    if(a.xi!=b.xi)
        return a.xi>b.xi;
    if(a.yi!=b.yi)
        return a.yi>b.yi;
}
int flag[120];
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&mac[i].xi,&mac[i].yi);
        for(int i=0;i<m;i++)
            scanf("%d%d",&pro[i].xi,&pro[i].yi);
        sort(mac,mac+n,cmp);
        sort(pro,pro+m,cmp);
        memset(flag,0,sizeof(flag));
        int tmp=-1;
        long long ans=0,count=0;
        for(int i=0,j=0;i<m;i++)
        {
            while(j<n&&mac[j].xi>=pro[i].xi)
            {
                flag[mac[j].yi]++;
                j++;
            }
            for(int k=pro[i].yi;k<=100;k++)
            {
                if(flag[k])
                {
                    flag[k]--;
                    ans++;
                    count+=(pro[i].xi*500+pro[i].yi*2);
                    break;
                }
            }
        }
        printf("%I64d %I64d\n",ans,count);
    }
    return 0;
}
View Code

 

posted @ 2018-12-19 22:08  lqsno1  阅读(77)  评论(0编辑  收藏  举报