贪心,排序,二分。。。

对x排序。

对于每个task,先把时间满足它的机器放入集合中,在二分找能处理它的最小等级的机器。

 

 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;

const int maxn = 200010;

struct node {
    int x,y;
    int price;
    int mak;
}mt[maxn];

bool cmp (const node &x,const node &y){
    if (x.x!=y.x)   return x.x>y.x;
    if (x.y!=y.y)   return x.y>y.y;
    return x.mak>y.mak;
}

int main (){
    int n,m;
    while (~scanf ("%d%d",&n,&m)){
        for (int i=0;i<n;i++){
            scanf ("%d%d",&mt[i].x,&mt[i].y);
            mt[i].mak=1;
        }
        for (int i=0;i<m;i++){
            scanf ("%d%d",&mt[n+i].x,&mt[n+i].y);
            mt[n+i].price=500*mt[n+i].x+2*mt[n+i].y;
            mt[n+i].mak=0;
        }
        sort (mt,mt+n+m,cmp);
        multiset<int> s;
        multiset<int> :: iterator it;
        int ans=0;
        int flag=0;
        long long sum=0;
        s.clear ();
        for (int i=0;i<n+m;i++){//cout<<mt[i].y<<endl;
            if (mt[i].mak)
                s.insert (mt[i].y);
            else if (!s.empty()){
                it=s.lower_bound (mt[i].y);
                if (it==s.end ())
                    continue ;
                flag--;
                ans++;
                sum+=mt[i].price;//cout<<sum<<endl;
                s.erase (it);
            }
        }//cout<<mt[0].mak;
        printf ("%d %I64d\n",ans,sum);
    }
    return 0;
}
posted on 2014-07-23 15:30  gfc  阅读(140)  评论(0编辑  收藏  举报