Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一A

Posted by 555333444 at 2015-11-05 16:52:44 on Problem 3614
#include <cstdio>
#include <queue>
#include <algorithm>
#define MAX_N 2600
using namespace std;
typedef pair<int,int> P;
P cow[MAX_N],bottle[MAX_N];
priority_queue<int,vector<int>,greater<int> > que;
int C,L,cur,result;
int main(){
    scanf("%d%d",&C,&L);
    for(int i = 0;i < C;++i){
        scanf("%d%d",&cow[i].first,&cow[i].second);
    }
    for(int i = 0;i < L;++i){
        scanf("%d%d",&bottle[i].first,&bottle[i].second);
    }
    sort(cow,cow + C);sort(bottle,bottle + L);
    for(int i = 0;i < L;++i){
        while(cur < C && cow[cur].first <= bottle[i].first){
            que.push(cow[cur].second);
            ++cur;
        }
        while(!que.empty() && bottle[i].second){
            int maxSPF = que.top();que.pop();
            if(maxSPF >= bottle[i].first){
                ++result;
                --bottle[i].second;
            }
        }
    }
    printf("%d\n",result);
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator