usaco Milking Cows

/*
ID: modengd1
PROG: milk2
LANG: C++
*/
#include <iostream>
#include <stdio.h>
#include <queue>
struct node
{
    int time;
    int O;
    node(int t,int o)
    {
        time=t;
        O=o;
    }
    node(){}
    bool friend operator <(node n1,node n2)
    {
        return n1.time>n2.time;
    }
};
using namespace std;
int N;
int main()
{
    freopen("milk2.in","r",stdin);
    freopen("milk2.out","w",stdout);
    int a,b;
    int ans1=0,ans2=0;
    int begint;
    int cows=0;
    scanf("%d",&N);
    priority_queue<node> Q;
    for(int i=0;i<N;i++)
    {
        scanf("%d%d",&a,&b);
        Q.push(node(a,1));
        Q.push(node(b,-1));
    }
    node now=Q.top();
    begint=now.time;
    while(!Q.empty())
    {

        now=Q.top();
        Q.pop();
        if(cows==0)
        {
             ans1=max(ans1,now.time-begint);
             begint=now.time;
        }
        cows+=now.O;
        if(cows==0)
        {
            ans2=max(ans2,now.time-begint);
            begint=now.time;
        }
    }
    cout<<ans2<<' '<<ans1<<endl;
    return 0;
}

  

posted on 2015-08-26 16:04  insaneman  阅读(120)  评论(0)    收藏  举报

导航