首页 > 代码库 > 【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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。