ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1245. Pictures

CAN ANYONE TELL ME WHAT'S WRONG WITH MY PROGRAM??
Posted by beiyz 21 Mar 2003 18:28
program ex;
type xx=record
     l,r,b,t:longint;
     end;
var a:array[1..1000] of xx;
    bb,tt,rr,ll,b1,t1,r1,l1:array[1..1000] of longint;
    c:xx;
    p1,q1,p2,q2,s,i,j,n,r,x,y,maxx,minx,maxy,miny:longint;

begin
  readln(n);
  fillchar(a,sizeof(a),0);
  maxx:=-maxint; maxy:=-maxint;
  minx:=maxint; miny:=maxint;
  for i:=1 to n do
  begin
    readln(r,x,y);
    a[i].l:=x-r; a[i].r:=x+r;
    a[i].t:=y+r; a[i].b:=y-r;
    if a[i].l<minx then minx:=a[i].l;
    if a[i].r>maxx then maxx:=a[i].r;
    if a[i].t>maxy then maxy:=a[i].t;
    if a[i].b<miny then miny:=a[i].b;
  end;
  p1:=maxx-minx;
  q1:=maxy-miny;
  if p1<100 then p1:=100; if q1<100 then q1:=100;
  s:=p1*q1;

  for i:=1 to n-1 do
    for j:=i+1 to n do
    if a[i].l>a[j].l then
    begin
      c:=a[i]; a[i]:=a[j]; a[j]:=c;
    end;
  bb[1]:=a[1].b; tt[1]:=a[1].t; rr[1]:=a[1].r;
  for i:=2 to n do
  begin
    if a[i].b<bb[i-1] then bb[i]:=a[i].b else bb[i]:=bb[i-1];
    if a[i].t>tt[i-1] then tt[i]:=a[i].t else tt[i]:=tt[i-1];
    if a[i].r>rr[i-1] then rr[i]:=a[i].r else rr[i]:=rr[i-1];
  end;
  b1[n]:=a[n].b; t1[n]:=a[n].t;
  for i:=n-1 downto 1 do
  begin
    if a[i].b<b1[i+1] then b1[i]:=a[i].b else b1[i]:=b1[i+1];
    if a[i].t>t1[i+1] then t1[i]:=a[i].t else t1[i]:=t1[i+1];
  end;
  for i:=1 to n-1 do
    if a[i+1].l>rr[i] then
    begin
      p1:=rr[i]-a[1].l;
      q1:=tt[i]-bb[i];
      p2:=rr[n]-a[i+1].l;
      q2:=t1[i+1]-b1[i+1];
      if p1<100 then p1:=100; if p2<100 then p2:=100;
      if q1<100 then q1:=100; if q2<100 then q2:=100;
      if p1*q1+p2*q2<s then s:=p1*q1+p2*q2;
    end;

  for i:=1 to n-1 do
    for j:=i+1 to n do
    if a[i].b>a[j].b then
    begin
      c:=a[i]; a[i]:=a[j]; a[j]:=c;
    end;
  ll[1]:=a[1].l; tt[1]:=a[1].t; rr[1]:=a[1].r;
  for i:=2 to n do
  begin
    if a[i].l<ll[i-1] then ll[i]:=a[i].l else ll[i]:=ll[i-1];
    if a[i].t>tt[i-1] then tt[i]:=a[i].t else tt[i]:=tt[i-1];
    if a[i].r>rr[i-1] then rr[i]:=a[i].r else rr[i]:=rr[i-1];
  end;
  l1[n]:=a[n].l; r1[n]:=a[n].r;
  for i:=n-1 downto 1 do
  begin
    if a[i].l<l1[i+1] then l1[i]:=a[i].l else l1[i]:=l1[i+1];
    if a[i].r>r1[i+1] then r1[i]:=a[i].r else r1[i]:=r1[i+1];
  end;
  for i:=1 to n-1 do
    if a[i+1].b>tt[i] then
    begin
      p1:=tt[i]-a[1].b;
      q1:=rr[i]-ll[i];
      p2:=tt[n]-a[i+1].b;
      q2:=r1[i+1]-l1[i+1];
      if p1<100 then p1:=100; if p2<100 then p2:=100;
      if q1<100 then q1:=100; if q2<100 then q2:=100;
      if p1*q1+p2*q2<s then s:=p1*q1+p2*q2;
    end;
  writeln(s);
end.