现在的位置: 首页 > 综合 > 正文

USACO 1.2.1 Milking Cows

2017年11月16日 ⁄ 综合 ⁄ 共 772字 ⁄ 字号 评论关闭
/*
ID:wconvey1
PROG:milk2
LANG:C++
*/


#include<iostream>
#include<algorithm>
#include<cstdio>
struct node{
		int s,e;
	};
node a[5010];
int cmp(const void *x,const void *y)
{
	if(((struct node *)x)->s!=((struct node *)y)->s)
         return ((struct node *)x)->s-((struct node *)y)->s;
	else 
		return ((struct node *)x)->e-((struct node *)y)->e;
}
int main()
{
	freopen("milk2.in","r",stdin);
    freopen("milk2.out","w",stdout);


	int n,i;
	scanf("%d",&n);
	int max=0,nomilk=0,temp=0,temp1;
	for(i=0;i<n;i++)
		scanf("%d %d",&a[i].s,&a[i].e);


	qsort(a,n,sizeof(a[0]),cmp);


	int start=a[0].s,end=a[0].e;
	max=a[0].e-a[0].s;
	for(i=1;i<n;i++){
        if(a[i].s<=end){
		   if(a[i].e>end)
			   end=a[i].e;
		}
		else{
			temp=end-start;
			if(temp>max)
				max=temp;
		//	start=a[i].s;
		//	end=a[i].e;
            temp1=a[i].s-end;
			if(temp1>nomilk)
				nomilk=temp1;


	        start=a[i].s;
			end=a[i].e;
		}
	}
	printf("%d %d\n",max,nomilk);
	return 0;
}


抱歉!评论已关闭.