luogu P2887 [USACO07NOV]防晒霜Sunscreen

贪心

#include
using namespace std;
const int N=2505,inf=999999999;
typedef pair<int,int>P;
P a[N],b[N];
bool cmp1(const P&a,const P&b){
    return a.second<b.second;
}
bool cmp2(const P&a,const P&b){
    return a.first<b.first;
}
int main(){
    int n,m,ans=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i){
        scanf("%d%d",&a[i].first,&a[i].second);    
    }
    for(int i=1;i<=m;++i){
        scanf("%d%d",&b[i].first,&b[i].second);
    }
    sort(a+1,a+n+1,cmp1);
    sort(b+1,b+m+1,cmp2);
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            if(a[i].first<=b[j].first&&a[i].second>=b[j].first&&b[j].second>0){
                ++ans;b[j].second--;
                break;
            }
        }
    }
    printf("%d",ans);
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/Dream-Runner/p/10139799.html

你可能感兴趣的:(luogu P2887 [USACO07NOV]防晒霜Sunscreen)