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 1116. Piecewise Constant Function

PLease, help...Problem 1116 I don't know what's going...
Posted by Vladimir Milenov Vasilev 11 Jan 2002 22:34
Here is my source...
Please, help if you can :))


program piecewice;
const max = 15000;
var ax,ay,av,bx,by,bv : array[1..max] of integer;
    endx,endy,endv : array[1..30000] of integer;
    i,j,n,m,ind,broi : longint;
Begin
read(n);
for i:=1 to n do read(ax[i],ay[i],av[i]);
read(m);
for i:=1 to m do read(bx[i],by[i],bv[i]);
broi:=0;
j:=1;
for i:=1 to n do
 Begin
  dec(j);
  while (bx[j+1]<ay[i])and(j<m) do
   Begin
    inc(j);
    if bx[j]=ax[i]
    then if by[j]=ay[i]
         then ay[i]:=ax[i]
         else if by[j]>ay[i]
              then ay[i]:=ax[j]
              else ax[i]:=by[j]
    else if bx[j]<ax[i]
         then if by[j]<=ax[i]
              then
              else if by[j]<ay[i]
                   then ax[i]:=by[j]
                   else ay[i]:=ax[i]
         else if bx[j]>ax[i]
              then if by[j]<ay[i]
                   then
                    Begin
                     inc(broi);
                     endx[broi]:=ax[i];
                     endy[broi]:=bx[j];
                     endv[broi]:=av[i];
                     ax[i]:=by[j];
                    End
              else
               Begin
                inc(broi);
                endx[broi]:=ax[i];
                endy[broi]:=bx[j];
                endv[broi]:=av[i];
                ay[i]:=ax[i];
               End;
   End;
  if ax[i]<ay[i]
  then
   Begin
    inc(broi);
    endx[broi]:=ax[i];
    endy[broi]:=ay[i];
    endv[broi]:=av[i];
    ax[i]:=by[j];
   End;
 End;
if broi=0 then writeln(0)
else write(broi);
for i:=1 to broi-1 do write(' ',endx[i],' ',endy[i],' ',endv[i]);
i:=broi;
if i>0 then writeln(' ',endx[i],' ',endy[i],' ',endv[i]);
End.