贪心,排序,二分。。。
#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; }
原文地址:http://www.cnblogs.com/gfc-g/p/3863148.html