USACO 1.2.1 – Milking Cows


/*
 ID: mohmdad5
 LANG: C++
 TASK: milk2
 */

#include <fstream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;

int main_milk2() {
	ofstream fout("milk2.out");
	ifstream fin("milk2.in");

	int n, a, b,A=1000000,B=0, best[3]={0}, cur=0, milking=2;
	char milk[1000001];
	memset(milk, 0, sizeof milk);
	fin >>n>>a>>b;
	for(int i=0; i<n ; i++, A=min(a, A), B= max(b, B), fin>>a>>b)
		memset(milk+a, 1, b-a);
	for(int i=A; i<B; i++)
		if(!i || milk[i]!=milking)
			best[milking] = max(best[milking], cur),cur =1, milking = milk[i] ;
		else
			cur++;
	fout << max(best[1], milking?cur : best[1]) << " " << max(best[0], milking? best[0] : cur)<<endl;
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: