首页 > 代码库 > 【USACO】milking cows

【USACO】milking cows

{ID: anniel11PROG: milk2LANG: PASCAL}Program milk2;Var    ans1,ans2,i,j,n,sum,head,tail:longint;    a:array[1..5000,1..2] of longint;    map:array[1..100000] of integer;    f:array[0..100000,1..2] of integer;Begin    fillchar(map,sizeof(map),0);    ans1:=0;    ans2:=0;    Assign(input, milk2.in); reset(input);    Assign(output, milk2.out); Rewrite(output);    Readln(n);    head:=maxlongint;    tail:=0;    fillchar(a,sizeof(a),0);    for i:=1 to n do    begin        readln(a[i,1],a[i,2]);        if a[i,1]<head then head:=a[i,1];        if a[i,2]>tail then tail:=a[i,2];        inc(map[a[i,1]]);        dec(map[a[i,2]]);    end;    for i:=head to tail do    begin        sum:=sum+map[i];        if sum>0 then f[i,1]:=f[i-1,1]+1 else f[i,1]:=0;        if f[i,1]>ans1 then ans1:=f[i,1];        if sum<=0 then f[i,2]:=f[i-1,2]+1 else f[i,2]:=0;        if f[i,2]>ans2 then ans2:=f[i,2];       // writeln(i, ,f[i,1], ,f[i,2]);    end;    writeln(ans1, ,ans2);    close(input);    close(output);End.

 

【USACO】milking cows