POJ 3622 multiset

思路:
放一个链接

是我太懒了
http://blog.csdn.net/mars_ch/article/details/52835978
嗯她教的我(姑且算是吧)
(一通乱搞就出来了…)

//By SiriusRen
#include <set>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 100500
int n,m,id=1;
long long ans;
struct Node{int a,b;}cow[N],grass[N];
bool cmp(Node a,Node b){return a.b>b.b;}
multiset<int>s;
multiset<int>::iterator it;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&cow[i].a,&cow[i].b);
    for(int i=1;i<=m;i++)
        scanf("%d%d",&grass[i].a,&grass[i].b);
    sort(cow+1,cow+1+n,cmp),sort(grass+1,grass+1+m,cmp);
    for(int i=1;i<=n;i++){
        while(grass[id].b>=cow[i].b)s.insert(grass[id].a),id++;
        it=s.lower_bound(cow[i].a);
        if(it==s.end()){puts("-1");return 0;}
        ans+=*it;
        s.erase(it);
    }
    printf("%lld\n",ans);
}

这里写图片描述

posted @ 2016-10-17 09:58  SiriusRen  阅读(114)  评论(0编辑  收藏  举报